Maven站点报告的良好测试效果,需要额外的配置才能进行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 demplicity表示,它调用了默认生命周期的test目标。Pitest插件没有。因此,是的,您必须将Pitest-Maven插件添加到构建部分,并将其绑定到生命周期阶段,即pre-site。我不建议将网站生命周期用于此目的,因为它不打算长期运行分析任务,但这取决于您。

因此,构建顺序为:

  • 建立生命周期
    • 构建模块(编译阶段)
    • 运行测试(测试阶段)
    • 运行突变覆盖范围(即在验证阶段)
  • 现场生命周期
    • pre site(mutation coverage);
    • 生成报告
    • 发布报告
    • ...

我建议使用配置文件,以便在每个构建上都不运行突变测试,并且您可以在需要时激活它(即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>

最新更新