运行 pitest 与 maven 无法找到或加载 org.pitest.coverage.execute.CoverageMinion
Running pitest with maven fails to find or load org.pitest.coverage.execute.CoverageMinion
我正在学习使用 pitest 进行突变测试,当我尝试使用 Maven 运行 时遇到问题。在我的 pom.xml 中,我有最严重的依赖性:
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest</artifactId>
<version>1.5.2</version>
</dependency>
我也有插件:
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<id>pit-report</id>
<!-- optional, this example attached the goal into mvn test phase -->
<phase>test</phase>
<goals>
<goal>mutationCoverage</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>0.12</version>
</dependency>
</dependencies>
<configuration>
<targetClasses>
<param>mypackage.myClass*</param>
</targetClasses>
<targetTests>
<param>mypackage*</param>
</targetTests>
</configuration>
</plugin>
然而,当我 运行 mvnw.cmd verify test -Dverbose
它报告说它找到了变异引擎,Junit 5 和 Junit 插件,将 junit 5 插件添加到 class 路径,添加pitest 到 class 路径,然后无法找到并加载 main class org.pitest.coverage.execute.CoverageMinion 并且不进行任何突变测试:
[INFO] --- pitest-maven:1.5.2:mutationCoverage (pit-report) @ myProject ---
[...]
[INFO] Found plugin : Mutant export plugin
[INFO] Found shared classpath plugin : Default mutation engine
[INFO] Found shared classpath plugin : JUnit 5 test framework support
[INFO] Found shared classpath plugin : JUnit plugin
[INFO] Found shared classpath plugin : TestNG plugin
[INFO] Adding org.pitest:pitest-junit5-plugin to SUT classpath
[INFO] Adding org.pitest:pitest to SUT classpath
[INFO] Mutating from C:\Users\myUser\myWorkspace\myProject\target\classes
[...]
13:20:27 PIT >> FINE : Running report with ReportOptions [targetClasses=[mypackage.myClass*], excludedMethods=[], excludedClasses=[], excludedTestClasses=[], codePaths=[C:\Users\myUser\myWorkspace\myProject\target\classes], reportDir=C:\Users\myUser\myWorkspace\myProject\target\pit-reports, historyInputLocation=null, historyOutputLocation=null, sourceDirs=[C:\Users\myUser\myWorkspace\myProject\src\main\java, C:\Users\myUser\myWorkspace\myProject\src\test\java], classPathElements=[C:\Users\myUser\myWorkspace\myProject\target\test-classes, C:\Users\myUser\myWorkspace\myProject\target\classes, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter.7.0\junit-jupiter-5.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter-params.7.0\junit-jupiter-params-5.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter-engine.7.0\junit-jupiter-engine-5.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\platform\junit-platform-engine.7.0\junit-platform-engine-1.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter-api.7.0\junit-jupiter-api-5.7.0.jar, C:\Users\myUser\.m2\repository\org\apiguardian\apiguardian-api.1.0\apiguardian-api-1.1.0.jar, C:\Users\myUser\.m2\repository\org\opentest4j\opentest4j.2.0\opentest4j-1.2.0.jar, C:\Users\myUser\.m2\repository\org\junit\platform\junit-platform-commons.7.0\junit-platform-commons-1.7.0.jar, C:\Users\myUser\.m2\repository\org\slf4j\slf4j-api.7.30\slf4j-api-1.7.30.jar, C:\Users\myUser\.m2\repository\org\pitest\pitest.5.2\pitest-1.5.2.jar, C:\Users\myUser\.m2\repository\org\pitest\pitest-junit5-plugin[=14=].12\pitest-junit5-plugin-0.12.jar, C:\Users\myUser\.m2\repository\org\pitest\pitest.5.2\pitest-1.5.2.jar], mutators=[], features=[], dependencyAnalysisMaxDistance=-1, jvmArgs=[-Djava.awt.headless=true], numberOfThreads=1, timeoutFactor=1.25, timeoutConstant=3000, targetTests=[^myPackage.*$], loggingClasses=[], maxMutationsPerClass=0, verbose=true, failWhenNoMutations=true, outputs=[HTML], groupConfig=TestGroupConfig [excludedGroups=[], includedGroups=[]], fullMutationMatrix=false, mutationUnitSize=0, shouldCreateTimestampedReports=true, detectInlinedCode=true, exportLineCoverage=false, mutationThreshold=0, coverageThreshold=0, mutationEngine=gregor, javaExecutable=null, includeLaunchClasspath=true, properties={}, maxSurvivors=0, excludedRunners=[], includedTestMethods=[], testPlugin=junit5, useClasspathJar=false, skipFailingTests=false]
13:20:27 PIT >> FINE : System class path is C:\Users\myUser\myWorkspace\myProject\.mvn\wrapper\maven-wrapper.jar
13:20:27 PIT >> FINE : Maximum available memory is 1796 mb
13:20:27 PIT >> FINE : MINION : Installing PIT agent
13:20:27 PIT >> INFO : MINION : Error: Could not find or load main class org.pitest.coverage.execute.CoverageMinion
最初我认为这是 classpath 的问题,考虑到错误消息,但上面的日志显示正在使用的 classpath 包括相关的 jar 和路径。我还能做错什么?提前致谢。
对于任何 运行 遇到同样问题的人,我的错误是我假设类路径是正确的,但事实并非如此。日志似乎没有考虑 classpath 环境变量的值,并且在我的计算机中该变量有一个值,但不应设置它。使用 set classpath= 取消设置解决了导致 pitest 错误的类路径问题。
我正在学习使用 pitest 进行突变测试,当我尝试使用 Maven 运行 时遇到问题。在我的 pom.xml 中,我有最严重的依赖性:
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest</artifactId>
<version>1.5.2</version>
</dependency>
我也有插件:
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<id>pit-report</id>
<!-- optional, this example attached the goal into mvn test phase -->
<phase>test</phase>
<goals>
<goal>mutationCoverage</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>0.12</version>
</dependency>
</dependencies>
<configuration>
<targetClasses>
<param>mypackage.myClass*</param>
</targetClasses>
<targetTests>
<param>mypackage*</param>
</targetTests>
</configuration>
</plugin>
然而,当我 运行 mvnw.cmd verify test -Dverbose
它报告说它找到了变异引擎,Junit 5 和 Junit 插件,将 junit 5 插件添加到 class 路径,添加pitest 到 class 路径,然后无法找到并加载 main class org.pitest.coverage.execute.CoverageMinion 并且不进行任何突变测试:
[INFO] --- pitest-maven:1.5.2:mutationCoverage (pit-report) @ myProject ---
[...]
[INFO] Found plugin : Mutant export plugin
[INFO] Found shared classpath plugin : Default mutation engine
[INFO] Found shared classpath plugin : JUnit 5 test framework support
[INFO] Found shared classpath plugin : JUnit plugin
[INFO] Found shared classpath plugin : TestNG plugin
[INFO] Adding org.pitest:pitest-junit5-plugin to SUT classpath
[INFO] Adding org.pitest:pitest to SUT classpath
[INFO] Mutating from C:\Users\myUser\myWorkspace\myProject\target\classes
[...]
13:20:27 PIT >> FINE : Running report with ReportOptions [targetClasses=[mypackage.myClass*], excludedMethods=[], excludedClasses=[], excludedTestClasses=[], codePaths=[C:\Users\myUser\myWorkspace\myProject\target\classes], reportDir=C:\Users\myUser\myWorkspace\myProject\target\pit-reports, historyInputLocation=null, historyOutputLocation=null, sourceDirs=[C:\Users\myUser\myWorkspace\myProject\src\main\java, C:\Users\myUser\myWorkspace\myProject\src\test\java], classPathElements=[C:\Users\myUser\myWorkspace\myProject\target\test-classes, C:\Users\myUser\myWorkspace\myProject\target\classes, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter.7.0\junit-jupiter-5.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter-params.7.0\junit-jupiter-params-5.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter-engine.7.0\junit-jupiter-engine-5.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\platform\junit-platform-engine.7.0\junit-platform-engine-1.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter-api.7.0\junit-jupiter-api-5.7.0.jar, C:\Users\myUser\.m2\repository\org\apiguardian\apiguardian-api.1.0\apiguardian-api-1.1.0.jar, C:\Users\myUser\.m2\repository\org\opentest4j\opentest4j.2.0\opentest4j-1.2.0.jar, C:\Users\myUser\.m2\repository\org\junit\platform\junit-platform-commons.7.0\junit-platform-commons-1.7.0.jar, C:\Users\myUser\.m2\repository\org\slf4j\slf4j-api.7.30\slf4j-api-1.7.30.jar, C:\Users\myUser\.m2\repository\org\pitest\pitest.5.2\pitest-1.5.2.jar, C:\Users\myUser\.m2\repository\org\pitest\pitest-junit5-plugin[=14=].12\pitest-junit5-plugin-0.12.jar, C:\Users\myUser\.m2\repository\org\pitest\pitest.5.2\pitest-1.5.2.jar], mutators=[], features=[], dependencyAnalysisMaxDistance=-1, jvmArgs=[-Djava.awt.headless=true], numberOfThreads=1, timeoutFactor=1.25, timeoutConstant=3000, targetTests=[^myPackage.*$], loggingClasses=[], maxMutationsPerClass=0, verbose=true, failWhenNoMutations=true, outputs=[HTML], groupConfig=TestGroupConfig [excludedGroups=[], includedGroups=[]], fullMutationMatrix=false, mutationUnitSize=0, shouldCreateTimestampedReports=true, detectInlinedCode=true, exportLineCoverage=false, mutationThreshold=0, coverageThreshold=0, mutationEngine=gregor, javaExecutable=null, includeLaunchClasspath=true, properties={}, maxSurvivors=0, excludedRunners=[], includedTestMethods=[], testPlugin=junit5, useClasspathJar=false, skipFailingTests=false]
13:20:27 PIT >> FINE : System class path is C:\Users\myUser\myWorkspace\myProject\.mvn\wrapper\maven-wrapper.jar
13:20:27 PIT >> FINE : Maximum available memory is 1796 mb
13:20:27 PIT >> FINE : MINION : Installing PIT agent
13:20:27 PIT >> INFO : MINION : Error: Could not find or load main class org.pitest.coverage.execute.CoverageMinion
最初我认为这是 classpath 的问题,考虑到错误消息,但上面的日志显示正在使用的 classpath 包括相关的 jar 和路径。我还能做错什么?提前致谢。
对于任何 运行 遇到同样问题的人,我的错误是我假设类路径是正确的,但事实并非如此。日志似乎没有考虑 classpath 环境变量的值,并且在我的计算机中该变量有一个值,但不应设置它。使用 set classpath= 取消设置解决了导致 pitest 错误的类路径问题。