ClassFormatError using JMockit with EMMA

时光总嘲笑我的痴心妄想 提交于 2019-12-05 22:53:29

I have been running into the same problem - this seems to have fixed it for me and hopefully will help anybody else as well.

If you're running this through ant, make sure you don't have vars in your javac target's debuglevel argument. The following target will cause the error.

<javac srcdir="${src}" destdir="${bin}" debug="on" debuglevel="lines,source,vars" nowarn="true" /> 

Change it to:

<javac srcdir="${src}" destdir="${bin}" debug="on" debuglevel="lines,source" nowarn="true">

This is probably a JMockit bug - very subtle and annyoing to find out.

I only saw this question today, but if you can, send me some tests that throw the ClassFormatError when running with EMMA, and I will try to find the bug in JMockit.

By the way, have you tried to use JMockit Coverage? Just add jmockit-coverage.jar to the classpath, and see what you get. Typically, this will produce (without any extra configuration) a nice HTML coverage report in the "coverage-report" dir under the working dir. It can't get any easier than that!

My team had the same issue. The concrete case was: using jMockit to mock static methods from a class in a unit-test suite running under TeamCity with EMMA as the coverage tool. The solution was the following:

Add a tear-down method to each test which mocked static methods:

@After
public void tearDown() throws Exception {
  Mockit.tearDownMocks(ClassWithStaticMethods.class);
}

Update jmockit from 1.5 to any recent version.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!