Table of Contents
Let’s imagine that you have a Legacy application you need to change. Of course, it has never been tested, and you should write the test before starting to work with the code.
Should you start with automation testing? But this is time-consuming, and there is never enough time in the software development. Perhaps, you’d rather start with E2E testing that helps you to cover the most critical issues? Or maybe it’s better to write unit tests since they are faster?
Working with legacy code is a non-trivial situation. In this article, we will consider the possible variants on how to do automation testing on an existing web application and decide which of them are better in certain situations.
What is a legacy system?
A legacy system is a software written with the use of old methods and technologies that operates without access to the Internet. 70% of corporate business applications are legacy ones. The statistics show that 60% of the IT budget is spent on Legacy system maintenance.
Legacy applications are maintained by very few people possessing the knowledge of the corresponding technologies and business processes. Usually, earlier versions of the software are used. The companies avoid upgrading the app since there is a risk that everything goes down. Most of the legacy apps don’t have proper documentation that makes it challenging to understand how they work.
Given the above-mentioned factors, replacing legacy systems may be a risky affair. With existing technologies, migration may be possible, but it involves time, maintenance, and testing the application. Since the legacy software is mainly written without automation testing, it’s a good idea to start introducing it to the app’s work. Let’s consider, what can be done for legacy system modernization.
It is always challenging to write automation tests for a legacy application. From where to start? How much to automate? What is the best strategy for test automation? Besides, there is never enough time and money, so you can’t test each and every module.
To decide on the first steps, you need to put priorities:
- What are the most critical areas of the application?
- Which key functionality brings the most money to the company?
- What are the biggest risks for the app systems?
- If you could improve only one thing in an application, what would it be?
What you shouldn’t do, is retrospectively write the tests for the user stories that successfully function as a part of the system. However, we need a set of key scenarios that check the system end-to-end to ensure that future development and maintenance won’t threaten the system functionality.
How to start legacy app testing
Here are some guidelines that can be used for testing an existing web application to find the key scenarios and a way to expand them.
The first thing for you to do testing is to get acquainted with the web application and its features. Start with exploring the structure of the website, its pages, the features and behavior of each one. For your convenience, you can present the website as a mind map. It will always help you to understand, how the pages are connected.
2) Gathering metrics
Analyze, how the web application is used by using the data of the marketing or analytics team. Most likely, your application has a tool like Google Analytics that is able to track user actions. This will help you to understand the user behavior and to figure out some common user journeys.
This information is necessary to decide, which test scenarios we should automate first in order to get maximum value within the shortest time.
3) Key scenarios automation
Once you have conducted the research, start automating core scenarios of the web application. For example, a typical user path in an e-commerce app is:
Homepage –> Search results –> Product details –> Customer login / Register –> Payment details –> Order confirmation
For us, it is important to check if the chain is working well and the user is able to place and pay the order. At this stage, we don’t need to check the page functionality in detail.
4) Increasing the feature coverage
Now we can expand the smoke regression pack to make the more extensive one. Let’s use our mind map and apply the state transition testing technique to build the scenarios.
First, we need to find the entry points of the system. They could be a landing page, a product details page or a special SEO-optimized one. Once we identified it, we need to find the features the user interacts with (a drop-down box, a search line, a filling up the user details, clicking a link).The next actions are as follows:
- Recording the initial state of the feature.
- Triggering the feature (some features will load the same page, but with different data, the other ones will transfer us to a different page). Here we check how the trigger is working.
- Once the state of the application changed, we make an assertion to check the new feature state.
Then, you can continue similarly on a different page or go to the initial state and interact with a different feature. Repeat the actions, until you cover all the important features in your mind map.
Test automation strategy for existing applications
We have told you about the general principles of implementing automation testing in a legacy web application. In this part of the article, we will speak about the particular steps and tools on how to automate web application.
Step 1. Static analysis
Static code analysis is a method of automatically examining the source code without running a program. It is performed at the earliest development stage before starting the software testing. Static analysis helps to find typos and code weaknesses and fix them at once.
Tools for static analysis include:
Lint tool (Linter) is an automated checker of your code for programming and stylistic errors. Linting is a basic stage of static code analysis.
Linter can make the code more readable:
– put the necessary tabs, spaces, semicolons, brackets – make a nice nested structure of tags – put the styles from tags to the separate <style> block – eliminate the odd spaces and blank entries.
Advanced linters can not only format the code but check the code logic, for example, to find dependencies that occupy memory, are but never used. Some of them can find potential memory leaks, circular dependencies, incomplete calls and clumsy classes.
There are many linters depending on your programming language. For example: ESLint, PC-Lint, Pylint, JSLint etc.
A code formatter parses your code and re-prints it according to the set of formatting rules.
– enforce the set maximum line length – make sure you don’t confuse single and double quotes – add commas at the end of each item – fix other formatting issues
Code formatter doesn’t touch the code functionality, only formatting. Example of code formatter: Prettier.
- Type checkers
Type checkers are static tools that detect errors in rarely used code paths and optimize the code by adding features like auto-completion. It detects the data types that are used and makes the code work faster and use less memory with the help of compilation.
Static type checkers are able to verify that the conditions hold all possible variants of program execution. It eliminates the need to repeat type checking during each program execution.
Examples of type checkers: TypeScript, Flow.
Step 2. E2E testing
We already know that it’s impossible to test each and every feature in the application, especially in a legacy one. We need to highlight the most important scenarios and run the test of them. Here comes end-to-end testing.
The best way to start is to write a test that will run on production and cover the most important user flow (please refer to your mind map).
Once the most important user path is tested, write the test scenarios for additional ones. But, if you do not have such an opportunity, you have already done an important job by testing the main one.
Step 3 – Unit testing
Once the main user paths are tested, we go to the next type of testing. You know that unit tests are simple types of automated tests. The biggest challenge in testing an existing web app is that it’s hard to decide where to start.
To start unit testing, choose a single pure function in your application and set up all the tools you need to have it tested. Once it’s done, it will become easier to write additional testing.
Having completed the previous steps, you already have all the necessary tools configured, and you are ready to write new tests. Now you can focus on writing the integration tests.
In integration testing, different program modules are logically united and tested as a single group. The goal of integration testing is to check the connection between the modules, data exchange, and find out the bugs in their interaction.
With all this pressure of work and deadlines, automating the existing application can be difficult and daunting. Our team can partner with you to take this process into our hands. Contact us to book a free consultation with our specialists.