In this hands-on, we will try applying PITest, a lightweight Java mutation tool, to one of Apache's open source project via the Maven build tool.
PITest is a Java mutation tool developed by Henry Coles. What distinguishes PITest from other mutation tools is the fact that it was developed by a practicing software engineer with the aim of actually applying mutation testing to real world projects. As such, PITest maintains a relativly simple set of mutation operators, for the sake of efficiency. On the other hand, it comes with plug-in supports with build tools (such as Maven) as well as an excellent report feature.
- You should have Jave8+ runtime environment.
- We will use the Apache Maven build tool. Install the current version.
- We will use Apache Commons Lang3 as our target system. Download the current version, and unzip the compressed source files.
- Inside the lang3 directory, you will find the Maven build congifuration file, named
pom.xml
. Open it. - Find
<plugins>
tag inpom.xml
. Add the following plugin entry inside the<plugins>
:
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.12.0</version>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<configuration>
<targetClasses>
<param>org.apache.commons.lang3.compare.*</param>
</targetClasses>
<targetTests>
<param>org.apache.commons.lang3.compare.*</param>
</targetTests>
</configuration>
</plugin>
- Now, execute Maven using the following:
$ mvn test-compile org.pitest:pitest-maven:mutationCoverage
- You can check the result by looking at
target/pit-reports
.