Proper setup for pitest-maven report-aggregate goal
Asked Answered
D

1

6

folks! I've tried to use the pitest-maven plugin in my Maven / Java project and it is apparently failing to generate an aggregated report (taking into consideration that I have a multi-module project). I gather some information from the official website and from several other sources, however, none of them was really helpful to define the proper configuration for this scenario. In a nutshell, my structure looks like:

Parent-Project

  • Child A
  • Child B
  • Child ...
  • Child N

In some of the submodules, it does make sense to have a pi-test being executed, others not. So to say, my configuration in general is.

Parent-module pom:

<profile>
        <id>run-pitest</id>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.pitest</groupId>
                        <artifactId>pitest-maven</artifactId>
                        <version>1.3.2</version>
                        <configuration>
                            <outputFormats>
                                <param>HTML</param>
                                <param>XML</param>
                            </outputFormats>
                            <!--<historyInputFile>${project.basedir}/pitHistory.txt</historyInputFile>-->
                            <!--<historyOutputFile>${project.basedir}/pitHistory.txt</historyOutputFile>-->
                            <mutators>
                                <mutator>CONDITIONALS_BOUNDARY</mutator>
                                <mutator>MATH</mutator>
                                <mutator>INCREMENTS</mutator>
                                <mutator>NEGATE_CONDITIONALS</mutator>
                            </mutators>
                            <verbose>true</verbose>
                            <exportLineCoverage>true</exportLineCoverage>
                            <testPlugin>testng</testPlugin>
                            <!--<reportsDirectory>${project.build.directory}/pit-reports</reportsDirectory>-->
                        </configuration>
                        <executions>
                            <execution>
                                <phase>test</phase>
                                <goals>
                                    <goal>mutationCoverage</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>report</id>
                                <phase>site</phase>
                                <goals>
                                    <goal>report-aggregate</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.pitest</groupId>
                    <artifactId>pitest-maven</artifactId>
                </plugin>
            </plugins>
        </build>
    </profile>

Child project that has mutations:

<plugins>
        <plugin>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-maven</artifactId>
            <configuration>
                <mutationThreshold>80</mutationThreshold>
                <exportLineCoverage>true</exportLineCoverage>
            </configuration>
        </plugin>
    </plugins>

And, finally, when I try to execute the phase site (as defined in the parent) even after I executed a clean install that created the files such as linecoverage.xml and mutations.xml, I'm getting this error:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.820 s
[INFO] Finished at: 2018-04-06T13:20:47+02:00
[INFO] Final Memory: 35M/514M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.pitest:pitest-maven:1.3.2:report-aggregate (report) on project my-parent: An error has occurred in PIT Test Report report generation. Failed to build: no lineCoverageFiles have been set -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
...

Does any of you have a clue if I did a bad configuration or if there is a better way to do any part of this setup?

Drill answered 6/4, 2018 at 11:35 Comment(0)
G
5

It seems that you are running into several problems at once :

  • When running report-aggregate the plugin analyze the dependencies of the module it runs in and expect everyone of them to have linecoverage.xml and a mutations.xml file. You have to have a submodule dedicated to report aggregation, and you should run report-aggregate only in this submodule.
  • report-aggregate can't deal with timestamped reports, it must be disabled
  • I couldn't make it work with the site phase. Not sure if it's a bug in the plugin or if I missed something (keeping the default phase works, but you need to get the report somehow, it won't be in the site).

Putting it all together :

in parent-module pom:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.pitest</groupId>
                <artifactId>pitest-maven</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <outputFormats>
                        <param>HTML</param>
                        <param>XML</param>
                    </outputFormats>
                    <!-- omitting mutators, testPlugin and verbose for brevity -->
                    <exportLineCoverage>true</exportLineCoverage>
                    <!--
                        it's currently not possible to aggregate timestamped
                        reports, so it must be disabled.
                     -->
                    <timestampedReports>false</timestampedReports>
                </configuration>
                <executions>
                    <execution>
                        <!--
                          Use an id to disable it in some submodules
                        -->
                        <id>pitest-mutation-coverage</id>
                        <phase>test</phase>
                        <goals>
                            <goal>mutationCoverage</goal>
                        </goals>
                    </execution>
                    <!--
                       NO report-aggregate here. Most of the time you don't
                       want it to run.
                    -->
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
    <!-- NO pitest here since its use will vary per submodule -->
</build>

in submodule with mutation :

<plugins>
    <plugin>
        <groupId>org.pitest</groupId>
        <artifactId>pitest-maven</artifactId>
        <!--
           You can put configuration here, but IMOHO it's better to have it
           in the parent pom. (so I leave it out here)
         -->
    </plugin>
</plugins>

in the submodule generating the report :

<!--
   Only include submodules where `mutationCoverage` is run.
 -->
<dependencies>
    <dependency>
        <groupId>you.groupId</groupId>
        <artifactId>submodule-A</artifactId>
    </dependency>
    <dependency>
        <groupId>you.groupId</groupId>
        <artifactId>submodule-B</artifactId>
    </dependency>
</dependencies>

and also

<plugins>
    <plugin>
        <groupId>org.pitest</groupId>
        <artifactId>pitest-maven</artifactId>
        <executions>
            <!--
               Using the execution id to change its phase to none disables
               mutationCoverage in this module.
               (not sure it's the best way to do it, but as long as it doesn't
               run you should be fine)
            -->
            <execution>
                <id>pitest-mutation-coverage</id>
                <phase>none</phase>
            </execution>
            <execution>
                <id>report</id>
                <!--
                  Keep default phase here.
                -->
                <goals>
                    <goal>report-aggregate</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>
Gopak answered 12/6, 2018 at 22:6 Comment(2)
While it sure seems like this should work, I continue to get the same error: 'Failed to build: no lineCoverageFiles have been set' even though the linecoverage and mutations have been generated in the submodules with mutationCoverage.xmlKaete
I wonder how the plugin knows where to look for those files knowing only the dependency, I imagine it extends the coverage aggregate, and that's how it does it, but something seems missing.Kaete

© 2022 - 2024 — McMap. All rights reserved.