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!