Running pitest with maven fails to find or load org.pitest.coverage.execute.CoverageMinion

2.2k views Asked by At

I am learning about mutation testing with pitest and facing problems when I try to run it with maven. In my pom.xml I have the pitest dependency:

<dependency>
    <groupId>org.pitest</groupId>
    <artifactId>pitest</artifactId>
    <version>1.5.2</version>
</dependency>

I also have the plugin:

<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>

However, when I run mvnw.cmd verify test -Dverbose it reports that it found the mutation engine, Junit 5 and the Junit plugin, adds the junit 5 plugin to the classpath, adds pitest to the classpath, and then fails to find and load main class org.pitest.coverage.execute.CoverageMinion and doesn't do any mutation testing:

[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

Initially I thought it would be a problem with the classpath, given the error message, but the above logs show that the classpath being used includes the relevant jars and paths. What else could I be doing wrong? Thanks in advance.

1

There are 1 answers

0
JustAnotherDeveloper On BEST ANSWER

For anyone running into the same problem, my mistake was that I assumed the classpath to be correct, but it wasn't. It seems the logs don't take into account the value of the classpath environment variable, and in my computer that variable had a value, when it shouldn't be set. Unsetting it with set classpath= solved the classpath issues that were causing the error with pitest.