Search code examples
javamavenpitest

Maven site reporting fine for surefire tests, needs extra config for pitest mutationCoverage


If I set up the <reporting> section in my pom as follows, I only get the surefire report, while the pitest report fails because it can't find any input.

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>2.9</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.19.1</version>
      </plugin>
      <plugin>
        <groupId>org.pitest</groupId>
        <artifactId>pitest-maven</artifactId>
        <version>1.1.10</version>
        <configuration>
          <targetClasses>
            <param>pricingengine.*</param>
          </targetClasses>
          <targetTests>
            <param>pricingengine.*</param>
          </targetTests>
        </configuration>
        <reportSets>
          <reportSet>
            <reports>
              <report>report</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>

To obtain the input to the pitest report so that it outputs to the site reports, I need to do this first:

mvn compile test-compile org.pitest:pitest-maven:mutationCoverage

Do I have to set up each of these in the <build> section as plugins with executions bound to the pre-site phase to get this to happen? Or is there a simpler solution with another plugin I'm not aware of?


Solution

  • The maven-surefire-report-plugin however explicity states, that it invokes the test goal of the default lifecycle. The pitest plugin doesn't. So yes, you have to add the pitest-maven plugin to the build section and bind it to a lifecycle phase, i.e. pre-site. I wouldn't recommend the use of the site lifecycle for that purpose as it is not intended for long-running analysis tasks, but that is up to you.

    So the build order is:

    • build lifecycle
      • build the module (compile phase)
      • run the test (test phase)
      • run the mutation coverage (i.e. in verify phase)
    • site lifecycle
      • pre-site (mutationCoverage);
      • generate reports
      • publish reports
      • ...

    I'd suggest to use a profile so the mutation test is not run on every build and you can activate it when needed (i.e. mvn site-P pit)

    <profile>
      <id>pit</id>
      <build>
        <plugins>
            <plugin>
                <groupId>org.pitest</groupId>
                <artifactId>pitest-maven</artifactId>
                <configuration>
                    <targetClasses>
                        <param>pricingengine.*</param>
                    </targetClasses>
                    <targetTests>
                        <param>pricingengine.*</param>
                    </targetTests>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>mutationCoverage</goal>
                        </goals>
                        <phase>pre-site</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
      </build>
    </profile>