Maven 站点报告 surefire 测试正常,需要额外配置以进行 pitest mutationCoverage

Maven site reporting fine for surefire tests, needs extra config for pitest mutationCoverage

如果我在我的 pom 中设置 <reporting> 部分如下,我只会得到 surefire 报告,而 pitest 报告失败,因为它找不到任何输入。

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>2.9</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.19.1</version>
      </plugin>
      <plugin>
        <groupId>org.pitest</groupId>
        <artifactId>pitest-maven</artifactId>
        <version>1.1.10</version>
        <configuration>
          <targetClasses>
            <param>pricingengine.*</param>
          </targetClasses>
          <targetTests>
            <param>pricingengine.*</param>
          </targetTests>
        </configuration>
        <reportSets>
          <reportSet>
            <reports>
              <report>report</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>

要获取 pitest 报告的输入以便它输出到站点报告,我需要先执行此操作:

mvn compile test-compile org.pitest:pitest-maven:mutationCoverage

我是否必须将 <build> 部分中的每个设置为插件,并将 executions 绑定到 pre-site 阶段才能实现?或者是否有更简单的解决方案和我不知道的另一个插件?

maven-surefire-report-plugin 然而明确指出,它调用默认生命周期的 test 目标。最糟糕的插件没有。所以是的,您必须将 pitest-maven 插件添加到构建部分并将其绑定到生命周期阶段,即 pre-site。我不建议为此目的使用站点生命周期,因为它不适用于长时间 运行ning 分析任务,但这取决于您。

所以构建顺序是:

  • 构建生命周期
    • 构建模块(编译阶段)
    • 运行测试(测试阶段)
    • 运行突变覆盖率(即在验证阶段)
  • 网站生命周期
    • 站点前 (mutationCoverage);
    • 生成报告
    • 发布报告
    • ...

我建议使用一个配置文件,这样突变测试就不会在每个构建上 运行,您可以在需要时激活它(即 mvn site-P pit

<profile>
  <id>pit</id>
  <build>
    <plugins>
        <plugin>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-maven</artifactId>
            <configuration>
                <targetClasses>
                    <param>pricingengine.*</param>
                </targetClasses>
                <targetTests>
                    <param>pricingengine.*</param>
                </targetTests>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>mutationCoverage</goal>
                    </goals>
                    <phase>pre-site</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>
</profile>