Java Mutation Testing With PIT

In this post we will talk about setting up Pitest for mutation testing.

Overview of mutation testing

Standard test coverage tools like Clover or EclEmma just check if a given statement or branch is executed by testcases. Mutation testing make sure that the a statement or a branch is executed and verified. Mutation testing achieve this via injecting mutants in the code. Testcases are executed after injecting mutants. If the testcases are still passing that means the mutants survived. Survived mutants are not a good indication of test coverage. Mutation testing make sure that testcases are written properly and every branch is verified. We will write another detailed post on mutation testing. In this post we will cover the steps involved in configuring the Pitest mutation testing tool.

Tools Required

  1. Eclipse
  2. Eclipse Maven Plugin
  3. Pitest 0.30 or above

Follow below given steps to add Pitest mutation testing to your project.

Create a maven project in Eclipse

Please refer to this post to create a java maven project in Eclipse.

Add Pitest repository in the maven settings.xml

Add Pitest plugin in pom.xml

Run the mutation testing against your code.

Make sure that you set the target classes correctly in pom.xml

Now run the mutation coverage goal.

mvn org.pitest:pitest-maven:mutationCoverage

Mutation coverage report will be given under the <<maven_project>>/target/pit-report/

Sample mutation coverage report

pit mutation testing

Eclipse Plugin

There is an Eclipse Pitest pulgin available for java mutation testing. Using this plugin you should be able to run the mutation testing within the Eclipse itself.

Leave a comment

Your email address will not be published. Required fields are marked *