如何使用 Maven 命令行参数从 PIT 突变测试中排除测试 类?

How to exclude test classes from PIT mutation test with maven command line arguments?

我正在尝试 运行 所有单元测试的变异测试,所以我需要从 运行.

中排除集成测试

我试过这些命令但没有成功:

mvn pitest:mutationCoverage -DExcludedClasses='**IntegrationTest'
mvn pitest:mutationCoverage -DExcludedTests='path.to.integrationtest.package.**' 

This page 声明有一种方法可以使用 --ExcludedClasses='**' 参数进行排除,但我猜这是为了使用 java 命令 intead of maven 启动它。

所以我的问题是:在 commandLine

上执行 运行 mvn pitest:mutationCoverage 命令时,是否有一个参数可以用来排除测试

根据 Maven plugin quickstart documentation for Pitest,有一个 excludedTestClasses 配置参数,您可以在其中指定应排除哪些测试。所以假设你所有的集成测试都在同一个包中,你应该能够做这样的事情:

<plugin>
    <groupId>org.pitest</groupId>
    <artifactId>pitest-maven</artifactId>
    <version>LATEST</version>
    <configuration>
        <excludedTestClasses>
            <param>path.to.integrationtest.package*</param>
        </excludedTestClasses>
    </configuration>
</plugin>

编辑:

为了在命令行上访问它,您可以 create a profile 由 属性 激活,并使用 属性 设置插件配置。 Maven默认合并配置,给你想要的结果。

像这样(未经测试):

<profiles>
  <profile>
    <activation>
      <property>
        <name>excludedTestPackage</name>
      </property>
    </activation>
    <build>
      <plugin>
        <groupId>org.pitest</groupId>
        <artifactId>pitest-maven</artifactId>
        <configuration>
          <excludedTestClasses>
            <param>${excludedTestPackage}</param>
          </excludedTestClasses>
        </configuration>
      </plugin>
    </build>
  </profile>
</profiles>

并在调用 Maven 时激活它:

mvn pitest:mutationCoverage -DexcludedTestPackage=path.to.integrationtest.package*

排除测试 类 的参数是 excludedTestClasses。这是区分大小写的(标准 maven 行为),您似乎将第一个字母大写,这意味着它不会被识别。

mvn pitest:mutationCoverage -DexcludedTestClasses='com.example.integrationtests.*'

会起作用。

请记住,glob 再次匹配包名称,而不是文件路径,并且当您直接调用目标时,您需要先有 运行 mvn testmvn test-compile确保所有必需的字节码都存在。

以下 link 首次涵盖了项目的 运行ning pitest,可能会有用。

https://pitest.groupcdg.com/docs/basic-maven-setup.html