John Goering
John Goering

Reputation: 39050

NoClassDefFoundError when trying to use JMockit Coverage

I am trying to use JMockit's code coverage abilities. Using the JVM parameter

-javaagent:jmockit.jar=coverage=.*MyClass.java:html::

I am able to run my tests (jmockit.jar and coverage.jar are on the classpath), unfortunately my log file says:

Loaded external tool: mockit.coverage.CodeCoverage=.*MyClass.java:html::
Loaded external tool: mockit.integration.junit3.JUnitTestCaseDecorator
Loaded external tool: mockit.integration.junit4.JUnit4ClassRunnerDecorator
Exception in thread "Thread-0" java.lang.NoClassDefFoundError
    at mockit.coverage.CodeCoverage$OutputFileGenerator.run(CodeCoverage.java:56)

...and no coverage file is generated. Has anyone gotten JMockit Coverage to work? If so, any thoughts as to what is causing this error? Thanks...

Answer: I needed to add coverage to the bootstrap entries rather than only the user entries (in the Eclipse run configuration)

Actual Answer The actual answer is that I was running the test with JUnit 3, but the coverage needs JUnit 4. That fixed things, and I didn't have to add any bootstrap entries.

Upvotes: 2

Views: 3287

Answers (2)

John Goering
John Goering

Reputation: 39050

I was running the test with JUnit 3, but the coverage needs JUnit 4. That fixed things, and I didn't have to add any bootstrap entries.

Upvotes: 2

Chris Kimpton
Chris Kimpton

Reputation: 5541

Random guess... Is coverage.jar on the classpath that jmockit uses - it might be a different one?

Upvotes: 1

Related Questions