Evolutionary Testing
The expansive domain of search-based software engineering (SBSE) has given light to evolutionary algorithms, an advanced software testing technique that employs evolutionary algorithms to generate test cases. This approach utilizes sophisticated optimization techniques to address and resolve complex problems in software testing.
Unlike manual test case generation, which is prone to human error, the use of evolutionary algorithms introduces a level of intelligence that can explore a diverse range of inputs. This exploration helps uncover edge cases that may be overlooked by human testers. The adaptability and scalability of evolutionary testing have made it a valuable tool for various testing objectives, including unit testing, integration testing, and performance evaluations.
Evolutionary Algorithms
Evolutionary algorithms are the special classes of algorithms in computer science that are inspired by the concept of biological evolution. The living organisms evolved and became more capable and complex era after era. This was an inspiration for the evolutionary algorithms that can evolve a solution to make it better.
They operate by starting with a set of potential solutions, referred to as a population. This population undergoes a series of genetic operations such as crossover (recombination of solutions) and mutation (random alterations). After each iteration, the population is refined, allowing the better-performing individuals to advance to the next generation. The quality of each solution is evaluated using a fitness function. Through numerous iterations, this process produces a population of solutions that are optimal or near-optimal.
What evolutionary algorithms have to do with testing?
Evolutionary testing is a technique that employs metaheuristic search methods to generate test cases for software. When testing software, it’s important to consider that the code often contains if-statements, loops, recursion, and other structures that introduce non-linearity. This non-linearity increases the complexity of optimizing test case generation.
In such scenarios, traditional neighborhood search methods such as hill-climbing may not yield the expected output. This is because these methods are not well-suited to deal with the non-linear nature of the software code. As a result, evolutionary testing, which utilizes metaheuristic approaches, becomes a more effective method for generating test cases in such complex environments.
Components of Evolutionary Algorithm
Population and generations
To apply evolutionary algorithms in the generation of test cases, one begins by initializing a large and diverse set of potential test cases. This means creating a wide range of different test cases that cover various scenarios and conditions that the software might encounter during its operation.
Subsequently, a subset of these test cases is randomly selected to constitute an individual within the population. This process involves randomly choosing a group of test cases from the initial set to form an individual within the population of test cases. This helps ensure that a diverse range of characteristics and conditions are represented within the population.
This process creates a rich initial population, where each individual is essentially a composite of several test cases, embodying a unique combination of characteristics. By combining different test cases into individuals within the population, the initial population becomes diverse and representative of various scenarios and conditions that the software might face. This diversity is essential for the evolutionary algorithm to effectively explore and identify effective test cases for the software.
Fitness function
The selection of a fitness function plays a crucial role in determining how effectively the final output meets the specified problem requirements. In the context of software testing, different fitness functions are applied based on the specific objectives of the testing process. These objectives can vary widely, ranging from ensuring functional correctness to optimizing performance or enhancing security.
One of the primary factors that influence the effectiveness, or “fitness,” of test cases is their code coverage. Code coverage refers to the extent to which the source code of a program is executed when a particular set of test cases is run. High code coverage implies that a significant portion of the codebase is tested, which in turn increases the likelihood of detecting defects and ensuring that the software behaves as expected under various conditions.
In addition to this, mutation testing is another approach used to determine the fitness of the function.
Mutation testing is an approach in which small intentional changes are made to the source code. It can be as small as altering an operator to change the flow of a block. Once the changes are made, the code is tested on the set of test cases. More failed test cases indicate that the test cases are effective. Hence, the fitness of the test cases can be the number of tests failed on the mutant source code.
Search space
When we talk about the search space in the context of using software, we are referring to all the potential scenarios that can be encountered while using the software. This includes the various inputs and outputs that the software can handle.
Inputs to the software can come in different forms.
- Gestures such as clicking, touching, or pressing keys. Additionally,
- files or data
- environment settings and configurations.
On the other hand, the outputs of the software encompass any action that the software can perform. This can range from displaying a message on the screen to sending a message over the internet, and everything in between.
Get Abhijith S Babu’s stories in your inbox
Join Medium for free to get updates from this writer.
When it comes to testing the software, an exhaustive test set should take into account all the possible combinations of inputs and outputs. This means that the search space should contain all the inputs and outputs that the system can encounter.
How to execute evolutionary testing?
Initiation
In evolutionary testing, the initial population of test cases is generated using a combination of random and heuristic approaches to ensure diversity. Test cases are structured based on defined input parameters and evaluated using a fitness function targeting specific objectives such as code coverage. This diverse initial population is essential for the evolutionary process, where test cases are progressively refined through selection, crossover, and mutation to optimize testing outcomes.
Selection
The test suite size can be predetermined, and a random set of test cases of this size can be designated as an individual. Multiple such individuals are generated to form the initial population for the first generation.
This approach provides a structured and diverse starting point for the evolutionary testing process, allowing for the exploration of various combinations of test cases within the initial population. Through subsequent generations, the evolutionary process aims to optimize the test suite by selectively breeding and evolving individuals based on their fitness in achieving testing objectives.
Crossovers and Mutations
From the current generation, we select individuals and do crossovers and mutations on them. The choice of individuals for crossovers and mutations depends on the fitness of those individuals. The higher the fitness of the individual, the more likely is the individual to be selected for crossover or mutation. This can improve the fitness of the upcoming generation. We still give a small probability for the individuals with less fitness to be selected, so as to avoid the possibility of being stuck at a local maxima.
After selecting the individuals, crossover, and mutation are applied to them. Crossover involves combining parts of two or more individuals to create a new test suite, enhancing the diversity of the next generation. Mutation introduces small random changes to some individuals in the test suite, thus exploring new cases. These processes iteratively refine the population, optimizing test cases to achieve better coverage and defect detection.
Evaluations and iterations
The new generation formed through evolutionary algorithms is likely to have a higher average fitness compared to the previous generation due to the selection and reproduction processes that favor more fit individuals. By repeatedly applying the steps of selection, crossover, and mutation over multiple iterations, the algorithm progressively refines the population. This iterative process results in a population that better adheres to the defined fitness function, improving the overall quality of solutions.
If mutation testing is used as a measure of fitness, incorporating changes to the mutant code after each iteration can introduce greater diversity. Mutation testing involves creating small, random changes in the code (mutants) to see if the test cases can detect them. By changing the mutant code in each iteration, the algorithm exposes the population to a wider variety of scenarios, which can help avoid local optima and ensure a more comprehensive search of the solution space.
This diversity is crucial as it prevents premature convergence to suboptimal solutions and encourages exploration of new areas in the solution space. Consequently, the population evolves to have not only higher fitness but also greater robustness and adaptability to various potential situations, ultimately leading to more effective and resilient solutions.
Benefits of Evolutionary testing
Automation
Evolutionary testing uses evolutionary algorithms to automate the generation and optimization of test cases. This approach reduces the manual effort needed to create and maintain test cases. By leveraging evolutionary algorithms, the testing process becomes more efficient and effective. These algorithms mimic the process of natural selection to evolve and improve the test cases over time. As a result, evolutionary testing can help identify and address software defects while reducing the burden on manual testers.
Effectiveness
Evolutionary testing enhances code coverage by generating test cases that explore previously untested paths, thereby improving verification across a broader spectrum of the software’s functionality. Additionally, it optimizes resource allocation, directing efforts toward defect-prone areas which increases testing efficiency.
Adaptability
Evolutionary testing demonstrates high adaptability, adjusting test cases dynamically as software requirements or the underlying codebase evolve. This capacity makes it particularly effective for projects characterized by continuous development and frequent updates, ensuring that testing processes remain relevant and comprehensive despite changes.
Reproduction of failures
Understanding the potential causes of software failure is essential as it can result from various factors, some of which may not be immediately apparent to the user. Users may encounter failures without a clear understanding of the actions or events that led to the issue. Reproducing the failure is crucial for thorough system testing and diagnosis.
A variant of evolutionary testing can help in reproducing failures by systematically exploring a wide range of input combinations and environmental conditions. Through the processes of selection, crossover, and mutation, it generates diverse and optimized test cases that can uncover hidden defects. When a failure is detected, the specific test case causing the failure is identified, making it easier to reproduce and analyze the issue, leading to more robust software.
Challenges
The following are some of the challenges in implementing evolutionary algorithms in testing.
Defining Fitness Function
Defining a fitness function for various kinds of testing in evolutionary algorithms presents distinct challenges. For instance, there are challenges in defining the fitness for performance testing primarily due to the multifaceted nature of performance metrics and the diverse conditions under which systems operate. Given these complexities, defining an effective fitness function for performance testing in evolutionary testing frameworks requires a deep understanding of both the software/hardware being tested and the specific performance metrics that are most relevant to the system’s operational success.
Computational Resources
Evolutionary testing can overutilize computational resources due to the need for managing large populations of test cases, conducting multiple generations of evolution, and performing intensive fitness evaluations. The processes of crossover and mutation further consume resources, and redundant operations can lead to inefficiencies. These factors collectively result in significant computational load during evolutionary testing.
Scalability
Scalability is a significant issue in evolutionary testing due to the intensive computational requirements for handling large populations of test cases. As the software system grows, the number of potential input combinations increases exponentially, demanding more memory and processing power. Multiple generations of evolution, combined with resource-intensive fitness evaluations, further exacerbate the computational load. Additionally, the processes of crossover and mutation require extensive calculations, which can become impractical for larger systems. Redundant evaluations of similar test cases can also lead to inefficiencies, making it challenging to scale evolutionary testing for complex and extensive software applications.
In short, we can say that leveraging evolutionary algorithms is a powerful approach to generating test cases. The efficiency of the output in terms of code coverage and defect detection makes it a valuable tool in software development. The algorithm takes care of the thorough exploration of the search space which not only improves robustness of the software, but also optimizes the resource utilization. As software systems grow in size and complexity, evolutionary testing will continue to be a handy tool in the developer’s armory.









