Mutation Testing

What is mutation testing?

Mutation testing is the process of altering the source code in a software product so as to create better test cases. The implementation of these test cases on a case by case basis helps in eliminating all the redundancies or ambiguities inherent in the chief code of the application program.

Execution of mutation testing

  • Bugs are deliberately added into the main internal code of the software under test through the creation of many different versions called mutants.
  • The test cases are applied to both the original and the mutant version of the software. The test cases are tweaked in such a way that faults are detected. This is easily achieved by introducing syntax based errors in the code.
  • If after comparing the results of the original and mutant, it is found that same output is generated, the mutant is said to be "killed" by the test case. The test case is then judged to be good enough for detection of changes between the original and mutant versions.
  • If there is difference in output, mutant is kept and said to be "alive" and it is inferred that more potent test cases are required to be developed to "kill" all the mutant versions.
  • The process is repeated for more mutants and subsequent development of improved and more effective test cases.

Different types of Mutation testing

Value Mutations: The code is modified by numerically altering the size of values or by changing the constants.

Decision mutations: Arithmetical, logical or relational operators such as AND, OR are changed to verify for design errors in the program code.

Statement mutations: Sometimes, problems crop up when a developer copy or pastes the code from a different destination. To check for such an anomaly, statements in the code are duplicated or deleted altogether from the code.

Merits of Mutation testing

  • All forms of code ambiguities are eliminated.
  • Detection of loopholes leads to development of more potent test cases.

Demerits of mutation testing

  • Tweaking the code requires sound programming knowledge; therefore the tester is required to have more than adequate coding skills.
  • Process of developing complex mutations and implementing them is time consuming and expensive.
  • Being time consuming, mutation testing requires the use of automation tools for faster implementation.