尝试使用 JMockit Coverage 时出现 NoClassDefFoundError
我正在尝试使用 JMockit 的代码覆盖能力。 使用 JVM 参数,
-javaagent:jmockit.jar=coverage=.*MyClass.java:html::
我可以运行我的测试(jmockit.jar 和coverage.jar 位于类路径上),不幸的是我的日志文件显示:
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)
...并且没有生成覆盖文件。 有人获得 JMockit Coverage 来工作吗? 如果是这样,有什么想法导致此错误吗? 谢谢...
答案:我需要向引导条目添加覆盖范围,而不仅仅是用户条目(在 Eclipse 运行配置中)
实际答案 实际答案是我正在使用 JUnit 3 运行测试,但覆盖范围需要 JUnit 4。这解决了问题,而且我不必添加任何引导条目。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用 JUnit 3 运行测试,但覆盖范围需要 JUnit 4。这解决了问题,而且我不必添加任何引导条目。
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.
随机猜测...coverage.jar 是否位于 jmockit 使用的类路径上 - 它可能是不同的?
Random guess... Is coverage.jar on the classpath that jmockit uses - it might be a different one?