0
2.5kviews
Mutation - Testing
1 Answer
1
93views

Mutation testing is the process of mutating some segment of code (putting some error in the code) and then testing this mutated code with some test data. If the test data is able to detect the mutations in the code, then the test data is quite good; otherwise we must focus on the quality of test data. Therefore, mutation testing helps a user create test data by interacting with the user to iteratively strengthen the quality of test data.

During mutation testing, faults are introduced into a program by creating many versions of the program, each of which contains one fault. Test data are used to execute these faulty programs with the goal of causing each faulty program to fail. Faulty programs are called mutants of the original program and a mutant is said to be killed when a test case causes it to fail. When this happens, the mutant is considered dead and no longer needs to remain in the testing process, since the faults represented by that mutant have been detected, and more importantly, it has satisfied its requirement of identifying a useful test case. Thus, the main objective is to select efficient test data, which have error-detection power. The criterion for this test data is to differentiate the initial program from the mutant. This ability to distinguish between the initial program and its mutant will be based on test results.

1, Primary Mutants:

Let us take an example of a C program to understand primary mutants.

enter image description here

We can consider the following mutants for the aforementioned example:

enter image description here

When the mutants are single modifications of the initial program that uses some operators, as shown, they are called primary mutants. Mutation operators are dependent on programming languages. as Note that each of the mutated statements represents a separate program. The results of the initial program and its mutants are shown below.

enter image description here

2. Secondary Mutants

Let us take another example program as shown below:

enter image description here

Now, mutants for this code may be as follows:

enter image description here

This class of mutants is called secondary mutants when multiple levels of mutation are applied on the initial program. In this case, it is very difficult to identify the initial program from its mutants.

3. Mutation Testing Process

The mutation testing process is discussed below:

  • Construct the mutants of a test program.
  • Add test cases to the mutation system and check the output of the program on each test case to see if it is correct.
  • If the output is incorrect, a fault has been found and the program must be modified and the process restarted.
  • If the output is correct, then that test case is executed against each live mutant.
  • If the output of a mutant differs from that of the original program on the same test case, the mutant is assumed to be incorrect and is killed.
  • After each test case has been executed against each live mutant, each remaining mutant falls into one of the following two categories.

    The mutant is functionally equivalent to the original program. An equivalent mutant always produces the same output as the original program; so no test case can kill it.

    The mutant is killable, but the set of test cases is insufficient to kill it. In this case, new test cases need to be created, and the process iterates until the test set is strong enough to satisfy the tester.

  • The mutation score for a set of test data is the percentage of non-equivalent mutants killed by that data. If the mutation score is $100 \%,$ then the test data is called mutation-adequate.

Please log in to add an answer.