Working With Legacy Code in Test Automation

When working in QA or Test Automation you are much more likely to be confronted with a legacy application with hundreds of thousands of code lines with missing documentation and test cases than finding well documented one with high test coverage and beautiful code. In many cases the legacy code has to be re-factored to improve testability. Therefore one critical skill in backend testing is to be able to work with legacy code.

When I start reading source code I start from a birds eye perspective. I first want to know how big the project is I am looking at.

Loc comes in handy in this situation to get a first general impression about the scale of the code base

Measuring complexity (McCabe)

Another very useful code metric in the situation described above is the McCabe complexity metric. This tool helps you to identify the most complex code. The complex areas need the most attention when it comes to quality assurance measures (documentation, testing, etc.). These areas usually contain the most defects, too.

Understanding the code structure using Callgraphs

Almost every time I am approaching a code base unknown to me I am looking for a certain functionality which I am particularly interested in. As soon as I understand the functionality I go to the next one and so on until I understand everything I need to. To identify relevant parts in the code a call graph proved to be very handy. The graph “lists” all the relevant modules and functions and shows in which order they are called. I always use the call graph as a “map” that helps me to navigate the code base unknown to me.

Installation of the pycallgraph tool (in Ubuntu)

apt-get install pycallgraph

Instead of starting your program with your python interpreter you just use pycallgraph to execute your script. For example run the scotch recording proxy within the pycallgraph tool:

pycallgraph run-recording-proxy -i scotch.* -e *.*

Call graphs get big very fast because the program usually calls a lot of library functions. For that reason I excluded everything except the scotch module from the diagram (-i and -e options), which I included.

Printing the callgraph

Most of the testing companies prefer using advanced technology elements in testing process to find quick and effective results. Callgraphs are usually big especially if you are working with a non trivial module. To be able to print those callgraphs in case you do not have a plotter the program Dia (Diagrams, UML, etc.) comes in very handy. To install it on a Ubuntu box just type:

Adding SSL to the site

In order to create certificates you need openssl and some configuration which is described in this section. If you want you can just install the provided sample certificates instead of creating your own (the certificates are contained in testing-software/ssh-sniffer). If you want to skip the certificate creation just jump to install certificates. Make sure you use this only as a local test scenario!

justgetblogging

Leave a Reply

Your email address will not be published. Required fields are marked *

Next Post

5 reasons one should invest in custom logo embroidery for their company

Mon Nov 4 , 2019
Although businesses think word of mouth advertising and a great looking website will get those sales, nothing beats the old tried and tested method of visual marketing: namely brand recognition. Companies like Starbucks, Apple, and Coca-Cola are easily recognized by their logos. These logos make it easy for people to […]
logo embroidery
%d bloggers like this: