Inspired by the last JUG Saxony visit, where Sven Ruppert held a talk about mutation testing I wanted to try out this possibility to develop useful test cases with high test coverage.
Unfortunately, the PITest plugin does not yet support Java 9 and JUnit 5 natively, so the example has currently following requirements regarding runtime environment :
- Java 8
- JUnit 4.12
- Maven 3.5
- PITest 1.3.*
- AssertJ 3.9.*
It is very easy to use PITest.
- Add the dependency to
pom.xmlfile:<dependency> <groupId>org.pitest</groupId> <artifactId>pitest-parent</artifactId> <version>${pitest.version}</version> <type>pom</type> <scope>test</scope> </dependency>
- Add plugin configuration to
pom.mxlfile<plugin> <groupId>org.pitest</groupId> <artifactId>pitest-maven</artifactId> <version>1.3.2</version> <configuration> <mutators> <mutator>ALL</mutator> </mutators> <targetClasses> <param>it.heber.sandbox.mutationtest.*</param> </targetClasses> <targetTests> <param>it.heber.sandbox.*</param> </targetTests> </configuration> </plugin>
The example above is the simplest. PITest provides various configurations very well described into PITest Maven Quick Start page.
To use pitest, all you have to do is activate the appropriate plugin for Maven
projects and start mvn pitest:mutationCoverage after running the test.
PITest provides very understandable reports. Together with the line code coverage, it measures the mutation coverage. There are statistics at package level. These reports can be transferred to a reporting server via the building/ test chain and thus made accessible.
Following steps are required to install the plugin:
-
Clone this repository to your developer workspace instance as
mutation-testproject:$ git clone https://github.com/UweHeber/mutation-test mutation-test -
Run following Maven commands:
mvn clean installmvn pitest:mutationCoverage
This example is licensed under the MIT license. See LICENSE for details.
