jMockit Report generation Fails with maven-surefire-plugin

342 views Asked by At

My project is a multi-module project.

I am trying to generate a test coverage report with jmockit within maven-surefire-plugin

When I build my maven project from the base directory : mvn clean package or mvn clean install, I get the following error

[INFO] Results:
[INFO]
[ERROR] Errors: 
[ERROR]   RestControllerTest.createA_PositiveWorkflow:61 ExceptionInInitializer
[ERROR]   RestControllerTest.getAById_PositiveWorkflow:98 NoClassDefFound Could not initialize class mockit.Expectations
[ERROR]   RestValidatorTest.validateA1:96 NoClassDefFound Could not initialize class mockit.Expectations
[ERROR]   RestValidatorTest.validateA2:115 NoClassDefFound Could not initialize class mockit.Expectations
[ERROR]   RestValidatorTest.validateA3:62 NoClassDefFound Could not initialize class mockit.Expectations
[ERROR]   RestValidatorTest.validateA4:79 NoClassDefFound Could not initialize class mockit.Expectations
[INFO]
[ERROR] Tests run: 16, Failures: 0, Errors: 6, Skipped: 0
[INFO]
[ERROR]

Java Version : Eclipse Temurin 17.0.5.8-hotspot

Maven Version : 3.6.3

Test Dependencies : jUnit, jMockit

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jmockit</groupId>
            <artifactId>jmockit</artifactId>
            <version>${jmockit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jmockit</groupId>
            <artifactId>jmockit-coverage</artifactId>
            <version>1.23</version>
            <scope>test</scope>
        </dependency>

 <!-- Propeties-->
 <java.release>17</java.release>
 <spring.boot.version>3.0.2</spring.boot.version>
 <spring.version>6.0.4</spring.version>
 <junit.version>5.9.2</junit.version>
 <jmockit.version>1.49</jmockit.version>

Below is my jMockit Coverage configured in maven-surefire-plugin

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>
                    -javaagent:"${settings.localRepository}"/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar
                </argLine>
                <systemPropertyVariables>
                    <coverage-output>html</coverage-output>
                    <coverage-outputDir>target/coverage-report</coverage-outputDir>
                    <coverage-classes>com.package.api.*</coverage-classes>
                    <coverage-excludes>com.package.api.constant.*,com.package.api.dto.*,com.package.api.model.*</coverage-excludes>
                </systemPropertyVariables>
                <argLine>--illegal-access=permit</argLine>
                <testFailureIgnore>true</testFailureIgnore>
            </configuration>
        </plugin>

Please let me know what else I need to do to generate report in defined Output directory.

Note : Running All tests from Intellij Run generated html report but not during Maven build.

Thanks in Advance

1

There are 1 answers

0
Jeff Bennett On

JMockit got somewhat crippled by Covid. Prior to March 2020, JMockit was developed mostly by one guy and was fairly regularly updated with the last pre-covid release being 1.49. When everyone went home, updates stopped, and the maintainer indicated that since he was not in the office any longer, he did not have time for updates. I don't believe there have been any updates to org.jmockit:jmockit since 1.49.

Around that same time, Java 17 came along, and there were some hiccups found in the 1.49 release related to Java 17. To keep things rolling, another guy has picked up some of the maintenance activities, and you can find later releases along the com.github.hazendaz.jmockit:jmockit line. Currently, 1.50 is out there.

I would say, if you are using JMockit with Java 17+, switch over to com.github.hazendaz.jmockit:jmockit. Fingers crossed, it will fix your issues.

I think jmockit-coverage is obsolete /unsupported (since 2016?) and you should consider switching to jacoco instead.