Pitest是否可以配置为对存在于Maven依赖jar文件中而非Maven模块本身的代码进行变异测试?

3
我们目前正在将并行构建引入到我们的Maven项目中,以减少构建时间。我们的Maven项目中有4个模块。
  1. main-app
  2. main-app-mutation-test
  3. main-app-integration-test
  4. main-app-acceptance-test
作为并行构建的一部分,我们并行构建2、3和4号模块(在第1个模块"main-app"之后)。我们需要先构建"main-app",因为其他3个模块依赖它。由于突变测试需要一段时间,所以我们不想在“main-app”中进行突变测试。 我们在"main-app-mutation-test"中使用Pitest进行变异测试。该模块包含的实际Java文件只是测试代码(在标准的Maven目录结构中)。我们希望进行变异测试的代码存在于"main-app"中,并通过标准的Maven依赖继承。以下是我们的Pitest插件配置(精简版):
    <plugin>
        <groupId>org.pitest</groupId>
        <artifactId>pitest-maven</artifactId>
        <version>1.4.10-DUMMY-SNAPSHOT</version>
        <executions>
            <execution>
                <id>default-cli</id>
                <goals>
                    <goal>mutationCoverage</goal>
                </goals>
                <configuration>
                    <targetClasses>
                        <targetClass>com.dummy.*</targetClass>
                    </targetClasses>
                    <outputFormats>
                        <outputFormat>HTML</outputFormat>
                    </outputFormats>
                    <mutationThreshold>99</mutationThreshold>
                    <coverageThreshold>99</coverageThreshold>
                    <detectInlinedCode>true</detectInlinedCode>
                    <threads>4</threads>
                    <timestampedReports>false</timestampedReports>
                    <skip>false</skip>
                    <skipTests>false</skipTests>
                </configuration>
            </execution>
        </executions>
    </plugin>
当我们运行pitest插件时,出现以下日志并且突变测试没有运行: [INFO] 跳过项目,因为: [INFO] - 项目没有测试,它是空的。 我希望'targetClasses'的值可以告诉pitest要突变测试哪些Java类。该项目还通过'maven-surefire-plugin'运行单元测试,但是找到要测试的测试和目标类没有问题。 因此我的问题是,即使它们在继承的jar文件中并且不存在于模块本身中,我们是否可以指定要突变测试的类?
1个回答

1
无法通过maven插件完成此操作,需要将单元测试与所测试的代码位于同一模块中。通常的做法是将变异测试作为配置文件的一部分运行。

我同意 Henry 的答案。作为一个解决方案,我只是使用 maven-resources-plugin 插件将源文件从“main-app”复制到“main-app-mutation-test”,完成变异测试后,我使用 maven-clean-plugin 进行清除。这有点瑕疵,但它让我能够同时运行变异、集成和验收测试,这带给我们很多好处。 - Nos

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,