Techopedia Explains Mutation Testing
Mutation testing is a simple but ingenious method used to validate source code correctness and the testing process. The concept was first coined by Richard Lipton in 1971, and there has been a surge of interest since that time.
Mutation testing's working mechanism is simple and straightforward. A piece of source code encompassing all unit tests is selected. After verifying all positive testing for a given source code, a mutation is introduced into the program.
The degree of mutation applied to a given code block may vary. A common mutation testing implementation involves replacing a logical operator with its inverse. For example, operator "! =" is used in place of "= =." In some cases, mutation involves rearranging lines to change the execution order or even deleting a few lines of code. Complex mutation testing levels may result in compilation errors.
Once a program is modified, a suite of unit tests are executed against the mutated code. The mutated code passes or fails the unit test, depending on the testing quality. A well-written unit test must detect mutated code errors, resulting in failure. A unit test that fails to detect code errors may require a rewrite.
Mutation testing facilitates the following advantages:
- Program code fault identification
- Effective test case development
- Detection of loopholes in test data
- Improved software program quality
- Elimination of code ambiguity
Disadvantages of mutation testing include:
- Difficult implementation of complex mutations
- Expensive and time-consuming
- Requires skilled testers with programming knowledge