【问题标题】:Proper setup for pitest-maven report-aggregate goal正确设置pitest-maven报告聚合目标
【发布时间】:2018-09-16 10:20:36
【问题描述】:

伙计们! 我尝试在我的 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>

最后,当我尝试执行 phase site(在父级中定义)时,即使我执行了创建文件的全新安装,例如 linecoverage.xml 和 mutations.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.
...

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

【问题讨论】:

    标签: maven-plugin mutation-testing pitest


    【解决方案1】:

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

    • 在运行report-aggregate插件时分析模块的依赖关系 运行并希望他们每个人都有linecoverage.xmlmutations.xml 文件。你必须有一个专门用于报告聚合的子模块,并且你应该在这个子模块中运行report-aggregateonly
    • 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>
    

    【讨论】:

      猜你喜欢
      • 2015-04-09
      • 2015-06-16
      • 1970-01-01
      • 2011-05-12
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 2020-04-10
      • 2015-07-08
      相关资源
      最近更新 更多