# 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.4 Phase 2: Test-Suite Generation for Fault Localization  
The goal of Phase 2 is to generate test suites that can perform fault localization when one or more test suites fails during Phase 1. Figure 5 shows the test-suite generation process for Phase 2. This phase makes it possible to propose the next test suite for fault localization, based on the results obtained from the Phase 1 test suites, and to perform fault localization with a small number of test suites. Firstly, the next test suite (\(T_{3}\)) is created based on the execution results of the test suites created in Phase 1 or previously executed test suites (\(T_{1}\),\(T_{2}\)). The test suite (\(T_{3}\)) is added to the list, and the next test suite (\(T_{i}\)) is created based on all of the executed test suites (\(T_{1}\sim T_{i-1}\)). This process can be repeated as many times as the test designer wishes (e.g., suspiciousness value, number of repeats). ```
1:functionFDTestSuiteGeneration\(\_\)Add\((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 \(>\)Where \(m_{num}\) is the number of mutants
4:for\(p=0\) to \(p_{num}\)do
5:for\(m=0\) to \(m_{num}\)do
6:ifExecution\((Chromosome[p],\ mutants[m])=false\) && \(!mutants[m].isKilled\)
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 3** Fault-detection test-suite generation (additional test suite). ```
1:functionFLTestSuiteGeneration\((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:\(\text{SetMutantSuspiciousness}()\) \(>\)Where \(m_{num}\) is the number of mutants
4:for\(g=0\) to \(g_{max}\)do \(>\)Where \(t_{s}\) is the number of previous test
5:for\(p=0\) to \(p_{num}\)do
6:for\(m=0\) to \(m_{num}\)do
7:ifExecution\((Chromosome[p],\ mutants[m])=false\)then
8:\(Chromosome[p].quality+=mutantSuspiciousness[m]\)
9:\(Chromosome[p].mutantcoverage[m]=true\)
10:endif
11:endfor
12:endfor
13:\(\text{Crossover}(Chromosome)\)
14:\(\text{Mutation}(Chromosome)\)
15:endfor
16:endfunction
17:functionSetMutantSuspiciousness\(()\)
18:for\(m=0\) to \(m_{num}\)do
19:for\(t=0\) to \(t_{snum}\)do
20:if\(previousTestSuites[t_{snum}].mutantcoverage[m]=true\)then
21:if\(previousTestSuites[t_{snum}].testResult=false\)then
22:\(mutantSuspiciousness[m]++\)
23:else
24:\(mutantSuspiciousness[m]=-1\)
25:break
26:endif
27:endif
28:endfor
29:endfor
30:endfunction
```  
**Algorithm 4** Fault-localizing test-suite generation. ```
1:functionFLTestSuiteGeneration\((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:\(\text{SetMutantSuspiciousness}()\) \(>\)Where \(t_{snum}\) is the number of mutants
4:for\(g=0\) to \(g_{max}\)do \(>\)Where \(t_{snum}\) is the number of previous test
5:for\(p=0\) to \(p_{num}\)do
6:for\(m=0\) to \(p_{num}\)do
7:ifExecution\((Chromosome[p],\ mutants[m])=false\)then
8:\(Chromosome[p].quality+=mutantSuspiciousness[m]\)
9:\(Chromosome[p].mutantcoverage[m]=true\)
10:endif
11:endfor
12:endfor
13:\(\text{Crossover}(Chromosome)\)
14:\(\text{Mutation}(Chromosome)\)
15:endfor
16:endfunction
```  
**Algorithm 5** Fault-detection test-suite generation (additional test suite). Algorithm 4 shows the pseudo code of the test-suite generation method for fault localization (Phase 2). The test-suite generation process for fault localization is almost the same as that in Phase 1, in that test suites are executed on mutants and the chromosomes (test suites) are evaluated and developed based on the results. The only difference is the test-suite evaluation method.