gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 01:45:39 24 4
gpt4 key购买 nike

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

父项目

  • child A
  • child B
  • child ...
  • child 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.xml 突变.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.
    ...

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

    最佳答案

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

  • 运行时report-aggregate该插件分析它的模块的依赖关系
    跑进来并期望他们每个人都有linecoverage.xmlmutations.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>

    关于maven-plugin - 正确设置pitest-maven报告聚合目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49691927/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com