Mutation Testing – Different, yet powerful way of testing your code

Being a developer, I perform Unit testing to make sure my code is bug free. But still, there is a chance that I might miss some bugs. While I was exploring some options to reduce this risk, I came to know about this wonderful concept.

Well, let’s see about Mutation Testing in this article.

What is Mutation Testing?

Mutation testing is a kind of a software testing methodology in which the source code itself is introduced with error (rather writing unit tests) and the results are checked for differences. It is basically a White Box Testing strategy.

The code after introducing the error is called the Mutant Code. The errors we introduce in the original code will be very small, so that the entire program will not be impacted.

The ultimate aim is to make sure the Mutant Code Version to fail. By doing this, we can assure the impact of the tests in the code.

How to achieve Mutation Testing?

  1. Errors are introduced into the source code of the program. These are called as Mutants. Each Mutant may have a single error
  2. Once the code is mutated, it’s time for us to run Unit Tests against the Mutated and Original Code. Make sure you use appropriate test data for the tests
  3. Let’s now compare the results of the original and mutant code. If the results are different, then it means that the mutant is killed by the test case. So, the test case is able to detect the change between the original and the mutant code. If the results are same, Mutant is kept alive, which means we need to write effective tests to break it.

Types of Mutation Testing

Mutation Tests can be achieved in 3 types –

  1. Statement Mutation – removal of a part of a code
  2. Value Mutation – parameters or arguments being changed
  3. Decision Mutation – modifying the decision making part of the code like if-else etc.,

Pros and Cons of Mutation Testing

Summary

To sum up, Mutation Testing is highly comprehensive and an effective way to make sure your code is bug free. Though it is costly and time consuming, it assures better results.

Image Credits:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Website Powered by WordPress.com.

Up ↑

%d bloggers like this: