5

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

父项目

  • 孩子A
  • 孩子B
  • 孩子 ...
  • 孩子 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>

具有突变的子项目:

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

最后,当我尝试执行阶段 站点(如父项中定义的那样)时,即使我执行了创建文件(例如linecoverage.xmlmutation.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.
...

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

4

1 回答 1

4

您似乎同时遇到了几个问题:

  • 运行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>

在带有突变的子模块中

<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>

在生成报告的子模块中

<!--
   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>

并且

<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>
于 2018-06-12T22:06:18.827 回答