使用maven运行pitest无法找到或加载org.pitest.coverage.execute.coverageminion

izj3ouym  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(765)

我正在学习用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插件添加到类路径,将pitest添加到类路径,然后找不到并加载主类org.pitest.coverage.execute.coveragenion,并且没有做任何变异测试:

[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\5.7.0\junit-jupiter-5.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.7.0\junit-jupiter-params-5.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.7.0\junit-jupiter-engine-5.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\platform\junit-platform-engine\1.7.0\junit-platform-engine-1.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.7.0\junit-jupiter-api-5.7.0.jar, C:\Users\myUser\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar, C:\Users\myUser\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar, C:\Users\myUser\.m2\repository\org\junit\platform\junit-platform-commons\1.7.0\junit-platform-commons-1.7.0.jar, C:\Users\myUser\.m2\repository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar, C:\Users\myUser\.m2\repository\org\pitest\pitest\1.5.2\pitest-1.5.2.jar, C:\Users\myUser\.m2\repository\org\pitest\pitest-junit5-plugin\0.12\pitest-junit5-plugin-0.12.jar, C:\Users\myUser\.m2\repository\org\pitest\pitest\1.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

一开始我认为类路径会有问题,给出错误消息,但是上面的日志显示所使用的类路径包括相关的jar和路径。我还能做错什么?提前谢谢。

dzjeubhm

dzjeubhm1#

对于遇到同样问题的人,我的错误是我假设类路径是正确的,但事实并非如此。日志似乎没有考虑classpath环境变量的值,在我的计算机中,这个变量有一个值,而不应该设置它。用set classpath=取消设置它解决了导致pitest错误的类路径问题。

相关问题