JMockit with Maven, Sonar, JaCoCo and Jenkins/Hudson

Updated:

We deployed our fresh new tests based on JMockit in our Jenkins/Sonar environment and surprise … no unit test works anymore. Even the tests that don’t use JMockit (simple JUnit) stopped to work. It was strange that during the build phase with test there was no problem but in the Sonar test phase the first JUnit test looped permanently.

It took a while to figure out the problem.

There is an incompatibility between JaCoCo and JMockit.

To solve the issue we added the jmockit javaagent to the maven-surefire-plugin:

<argLine> 
    -javaagent:"${settings.localRepository}"/com/googlecode/jmockit/jmockit/0.999.15/jmockit-0.999.15.jar 
</argLine> 

Here how it looks like the plugin:

<plugin>  
 <groupId>org.apache.maven.plugins</groupId>  
 <artifactId>maven-surefire-plugin</artifactId>  
 <version>2.12</version>  
 <configuration>  
<argLine>-javaagent:"${settings.localRepository}"/com/googlecode/jmockit/jmockit/0.999.15/jmockit-0.999.15.jar</argLine>  
 </configuration>  
</plugin> 

After this change the test are executed correctly and the incompatibility between JaCoCo and JMockit solved!


Fullstack Angular / Java application quick start guide.
WebApp built by Marco using SpringBoot 3.2.4 and Java 21. Hosted in Switzerland (GE8).