pitest-maven 报告聚合目标的正确设置

Fer*_*pos 5 mutation-testing maven-plugin pitest

伙计们!我尝试在我的 Maven / Java 项目中使用 pitest-maven 插件,但显然无法生成汇总报告(考虑到我有一个多模块项目)。我从官方网站和其他几个来源收集了一些信息,但是,它们都没有真正帮助定义此场景的正确配置。简而言之,我的结构如下所示:

父项目

  • 孩子A
  • 儿童乙
  • 孩子 ...
  • 儿童 N

在某些子模块中,执行 pi-test 确实有意义,而其他子模块则没有。可以这么说,我的配置一般是。

父模块 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>
Run Code Online (Sandbox Code Playgroud)

具有突变的子项目:

<plugins>
        <plugin>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-maven</artifactId>
            <configuration>
                <mutationThreshold>80</mutationThreshold>
                <exportLineCoverage>true</exportLineCoverage>
            </configuration>
        </plugin>
    </plugins>
Run Code Online (Sandbox Code Playgroud)

最后,即使在我执行了创建linecoverage.xmlmutations.xml等文件的全新安装之后,当我尝试执行阶段 站点(如父项中定义的那样)时,我也会收到此错误:

[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.
...
Run Code Online (Sandbox Code Playgroud)

如果我做了错误的配置,或者是否有更好的方法来完成此设置的任何部分,你们中有人有线索吗?

小智 5

看来您同时遇到了几个问题:

  • 运行report-aggregate插件时,分析它运行的模块的依赖关系,并期望每个模块都有linecoverage.xml一个mutations.xml文件。您必须有一个专用于报告聚合的子模块,并且您应该report-aggregate 在该子模块中运行。
  • report-aggregate无法处理带时间戳的报告,必须禁用它
  • 我无法让它与site相位一起工作。不确定这是否是插件中的错误,或者我是否遗漏了某些内容(保持默认阶段有效,但您需要以某种方式获取报告,它不会出现在站点中)。

把它们放在一起:

在父模块 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>
Run Code Online (Sandbox Code Playgroud)

在带有突变的子模块中

<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>
Run Code Online (Sandbox Code Playgroud)

在生成报告的子模块中

<!--
   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>
Run Code Online (Sandbox Code Playgroud)

并且

<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>
Run Code Online (Sandbox Code Playgroud)