Even with TDD, the quality or coverage of the existing Unit Tests are always a concern for the developer. “Have I done enough ?” That’s one question that haunts him throughout.
Mutation Testing is a structural testing method that attempts to add more value to Unit Tests by aiding in identifying the ‘misses’ in Unit Tests. The central idea behind is to write Mutant of existing code, each of the mutant varying each other by a single change.
For example, Let’s think about the following code.
int TestMethod(int CurrentValue) { if(CurrentValue<=3) return 100; else return 200; }
One of the mutants of the method would be replacing the decision parameter “”. The Mutant would look like following.
int TestMethod(int CurrentValue) { if(CurrentValue>3) return 100; else return 200; }
Idea behind the Mutation Testing Approach is to ensure that the Testing Data set is near complete and adequate to identify all possibles that the code could have. The focus would then shift to create Test Cases that would kill as much as mutants as possible.
- Decision Mutations – Conditions are changed for checking design errors, typically relational, logical and arithmetic operators.
- Value Mutations – Typically focused on changing the values (especially constants) to detect the impact/error
- Statement Mutations – Statements are removed/duplicated.