JMockit – initialization problem

The accepted answer has fallen a little out of date regarding the links so it’s worth mentioning the various solutions directly.

To fix this problem do one of the following:

1 – Specifiy a javaagent

Add this to your JUnit execution environment (for your version):


2 – configure the Surefire plugin in Maven to avoid it

Add the following to your Maven configuration (choose your own versions)

<!-- JMockit must be before JUnit in the classpath -->
<!-- Standard unit testing -->

Ensure that your Surefire plugin is configured as follows (for your particular versions):


3 – Use the JUnit @RunWith annotation

Add this JUnit runner annotation on each and every test class

public class ExampleTest {}

Leave a Comment