# Model-Based Test Suite Generation Using Mutation Analysis for Fault Localization
## 3 Model-Based Test-Suite Generation Using Mutation Analysis
### Test-Suite Generation
#### 3.3.3 Phase 1: Test-Suite Generation for Fault Detection  
In the first phase, a high-quality test suite is generated through mutation analysis. The test suites in this phase are aimed toward detecting faults; therefore, they are generated via the genetic algorithm into the form that detects the largest number of mutants. At least one failed test is required to create test suites for fault localization in Phase 2. Phase 1 is a step for finding a failed test. If a failed test was already identified, the process can be skipped.  
The overall order of the algorithm consists of initialization, test execution, evaluation, and genetic operation. The test cases generated through initialization and the failing test cases inserted between them are executed with the mutants to determine how many mutants are killed and to evaluate the solution. The genetic algorithm is applied to the best solutions to generate the next generation, which inherits good traits. Test execution is performed on the mutants again to check the quality of the  
Figure 4: Chromosome form and gene operations used in this study.  
improved solution. Hence, the solution is improved using the genetic operations, and the process is repeated to generate a test input that is advantageous for fault localization. Algorithm 2 shows the pseudo code of the fault-detection test-suite generation algorithm used in this study.  
```
1:functionFDTestSuiteGeneration(\(TP\)) \(>\)Where \(g_{max}\) is the number of max generations
2:\(Chromosome=\) InitializeTestSuite(\(TP\), \(p_{num}\)) \(>\)Where \(p_{num}\) is the number of populations
3:for\(g=0\) to \(g_{max}\)do
4:for\(p=0\) to \(p_{num}\)do
5:for\(m=0\) to \(n_{num}\)do
6:ifExecution(\(Chromosome[p]\), \(mutants[m])=false\)
7:\(Chromosome[p].quality++\)
8:\(Chromosome[p].mutantcoverage[m]=true\)
9:endif
10:endfor
11:endfor
12:\(\text{Crossover}(Chromosome)\)
13:\(\text{Mutation}(Chromosome)\)
14:endfor
15:endfunction
```  
**Algorithm 2** Fault-detection test-suite generation.  
In Algorithm 2, genetic operations are repeated \(g_{max}\) times and the quality of the test suites improves with the number of repeated generations. However, as \(g_{max}\) increases, the time required to generate the test suites increases. Therefore, we set the value of \(g_{max}\) such that it is suitable for testing. If the test is important, the value of \(g_{max}\) can be increased. In each generation, all test suites are performed on all of the mutants. If the results are false (i.e., if the mutant is killed), the quality of the test suites improves. Algorithm 2 is executed twice because it is designed to allow each TP to obtain transition coverage of 50%. Test cases for all transitions are required for fault detection; therefore, random pairs of TPs that cover all transitions are selected, and each is inserted into the algorithm. When this process is complete, the test target program is executed to determine whether the failed test suites exist. If there are no failed test suites, a random TP is selected that is different from the previously selected TP, and the process is repeated until a failed test suite is discovered. If the additional test-suite generation process is repeated, it is more effective to assign high-quality values to chromosomes (test suites) with mutants that were never killed.  
Algorithm 3 shows the pseudo code for the test-suite generation algorithm when additional test suites are generated. It differs from Algorithm 2 in that the chromosomes are only assigned scores when a mutant that never previously died is killed. Thus, the test suites are developed so that mutants that were never discovered are found and the fault-detection probability increases. Even if a single failed test suite exists, this process can be repeated if there is a high-risk test target.