我这里有一个奇怪的问题,我找不到原因:
当在命令行上将 pitest 与 maven(和 java 11)一起使用时,它按预期工作,但是当通过声明性管道在 Jenkins-Server 上运行它时,它会导致错误。
来 self 的 maven pom 的部分:
<build>
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.4.8</version>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>0.8</version>
</dependency>
</dependencies>
<configuration>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
来 self 的 Jenkinsfile 的部分:
stage('MutationTesting')
{
steps
{
bat 'mvn --batch-mode org.pitest:pitest-maven:mutationCoverage'
}
}
在此之前将从管道调用以下 Maven 命令:
mvn --batch-mode clean
mvn --batch-mode compile
mvn --batch-mode compiler:testCompile surefire:test -Dmaven.test.failure.ignore=true
当在命令行上准确调用这些命令时,pitest 可以完美运行。
当比较日志记录结果时,它们几乎相等。
命令行的日志输出:
PIT >> FINE : Maximum available memory is 3609 mb
PIT >> FINE : MINION : Installing PIT agent
PIT >> INFO : Sending 13 test classes to minion
PIT >> INFO : Sent tests to minion
PIT >> INFO : MINION : 08:51:20 PIT >> FINE : Expecting 13 tests classes from parent
PIT >> FINE : Tests classes received
PIT >> INFO : Checking environment
PIT >> INFO : MINION : 08:51:20 PIT >> INFO : Found 1 tests
PIT >> INFO : MINION : 08:51:20 PIT >> INFO : Dependency analysis reduced number of potential tests by 0
PIT >> INFO : MINION : 08:51:20 PIT >> INFO : 1 tests received
PIT >> INFO : MINION : 08:51:20 PIT >> FINE : Running 1 units
PIT >> INFO : MINION : 08:51:20 PIT >> FINE : Gathering coverage for test Description [testClass=de.test.Tests, name=creation()]
PIT >> FINE : Coverage generator Minion exited ok
PIT >> INFO : Calculated coverage in 0 seconds.
PIT >> FINE : Used memory after coverage calculation 42 mb
PIT >> FINE : Free Memory after coverage calculation 201 mb
[... Mutations output cut]
Jenkins-Pipeline 的日志输出:
PIT >> FINE : Maximum available memory is 1813 mb
PIT >> FINE : MINION : Installing PIT agent
PIT >> INFO : Sending 13 test classes to minion
PIT >> INFO : Sent tests to minion
PIT >> INFO : MINION : 08:46:28 PIT >> FINE : Expecting 13 tests classes from parent
PIT >> FINE : Tests classes received
PIT >> INFO : Checking environment
PIT >> INFO : MINION : 08:46:29 PIT >> INFO : Found 1 tests
PIT >> INFO : MINION : 08:46:29 PIT >> INFO : Dependency analysis reduced number of potential tests by 0
PIT >> INFO : MINION : 08:46:29 PIT >> INFO : 1 tests received
PIT >> INFO : MINION : 08:46:29 PIT >> FINE : Running 1 units
PIT >> INFO : MINION : 08:46:29 PIT >> FINE : Gathering coverage for test Description [testClass=de.test.Tests, name=creation()]
PIT >> FINE : Coverage generator Minion exited ok PIT >> INFO : Calculated coverage in 1 seconds. PIT >> FINE : Used memory after coverage calculation 43 mb PIT >> FINE : Free Memory after coverage calculation 177 mb PIT >> INFO : Created 0 mutation test units [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.644 s [INFO] Finished at: 2019-06-06T08:46:29+02:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.pitest:pitest-maven:1.4.8:mutationCoverage (default-cli) on project multiuploader: Execution default-cli of goal org.pitest:pitest-maven:1.4.8:mutationCoverage failed: No mutations found. This probably means there is an issue with either the supplied classpath or filters. [ERROR] See http://pitest.org for more details.
所以我只能假设环境存在差异 - 但哪一个呢?或者它是 pitest 中的错误?
最佳答案
最有可能的问题是 pitest 正在由 jenkins 在未编译测试的环境中执行。
最稳健的方法是将 pitest 绑定(bind)到配置文件中的测试阶段,而不是直接调用目标。
<profile>
<id>pitest</id>
<build>
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.4.8</version>
<executions>
<execution>
<id>pitest</id>
<phase>test</phase>
<goals>
<goal>mutationCoverage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
然后可以运行 Pitest
mvn -Ppitest test
关于java - 为什么 pitest 在命令行上使用 maven,而不是在 Jenkins-Pipeline 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56489275/