Mark Reddy bio photo

Mark Reddy

Modern Java programmer with an interest in distributed systems

Twitter Google+ LinkedIn Instagram Github

Recently I deployed a new batch of unit tests based on the JMockit framework in our new Jenkins + Sonar environment and after building successfully the tests were hanging during sonar analysis. 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, however I found that there is an incompatibility between JaCoCo and JMockit.

To solve the issue I 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, the incompatibility between JaCoCo and JMockit had been solved and the analysis ran to completion show 98% unit test coverage!