Search code examples
javamutation-testingpitest

Can pitest be configured to mutation test code that exists a maven dependent jar file and not the maven module itself?


We are currently introducing parallel builds into our maven project to reduce build times. We have 4 modules in our maven project.

  1. main-app
  2. main-app-mutation-test
  3. main-app-integration-test
  4. main-app-acceptance-test

As part of the parallel build, we are building modules 2,3 and 4 in parallel (after module 1 - 'main-app'). We need to build 'main-app' first as the other 3 modules depend on it. Mutation testing takes a while so we don't want to do it in the 'main-app'.

We use pitest for mutation testing in 'main-app-mutation-test'. The only actual java files this module contains is test code (in the standard maven directory structure). The code we wish to mutation test exists in the 'main-app' and is inherited via a standard maven dependency. Here is our pitest plugin config (trimmed down):

    <plugin>
        <groupId>org.pitest</groupId>
        <artifactId>pitest-maven</artifactId>
        <version>1.4.10-DUMMY-SNAPSHOT</version>
        <executions>
            <execution>
                <id>default-cli</id>
                <goals>
                    <goal>mutationCoverage</goal>
                </goals>
                <configuration>
                    <targetClasses>
                        <targetClass>com.dummy.*</targetClass>
                    </targetClasses>
                    <outputFormats>
                        <outputFormat>HTML</outputFormat>
                    </outputFormats>
                    <mutationThreshold>99</mutationThreshold>
                    <coverageThreshold>99</coverageThreshold>
                    <detectInlinedCode>true</detectInlinedCode>
                    <threads>4</threads>
                    <timestampedReports>false</timestampedReports>
                    <skip>false</skip>
                    <skipTests>false</skipTests>
                </configuration>
            </execution>
        </executions>
    </plugin>

But when we run the pitest plugin, we get the following logging and the mutation tests are not ran.

[INFO] Skipping project because:
[INFO] - Project has no tests, it is empty.

I had hoped the 'targetClasses' value would tell pitest what java classes to mutation test. This project also runs the unit tests via 'maven-surefire-plugin' and it finds both the test and target classes to be tested no problem.

So my questions is, can we specify the classes to be mutation tested, even if they are in an inherited jar file and don't exist in the module itself?


Solution

  • This cannot be done via the maven plugin, it requires unit tests to be in the same module as the code they test.

    The usual approach is to run mutation testing as part of a profile.