本文介绍了结合使用JMockit和EMMA的ClassFormatError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用EMMA来衡量一些使用JMockit的JUnit测试的覆盖率.但是,当我尝试使用EMMA进行测试后运行JMockit测试时,大约四分之一的测试失败并显示以下错误:

I am trying to use EMMA to measure coverage of some JUnit tests that use JMockit. But when I try to run the JMockit tests after instrumenting with EMMA, about a quarter of the tests fail with the following error:

com.logstorage.engine.sensor.SensorManagerTest.setUpBeforeClass(SensorManagerTest.java:98)
    java.lang.ClassFormatError
    at sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)
    at sun.instrument.InstrumentationImpl.redefineClasses(InstrumentationImpl.java:150)
    at mockit.internal.RedefinitionEngine.redefineMethods(RedefinitionEngine.java:152)
    at mockit.internal.RedefinitionEngine.redefineMethods(RedefinitionEngine.java:139)
    at mockit.internal.RedefinitionEngine.redefineMethods(RedefinitionEngine.java:73)
    at mockit.Mockit.setUpMock(Mockit.java:235)
    at com.myapp.MyTest.setUpBeforeClass(MyTest.java:98)

我看不到关于哪些测试失败和哪些没有失败的任何模式.我想这只是JMockit中的错误,但是有人知道解决方法吗?

I can't see any pattern as to which tests fail and which don't. I guess this is just a bug in JMockit, but does anybody know a workaround?

我发现了一个非常相似的问题,即使用EMMA获取ClassFormatError吗?"但是该解决方案对我不起作用(我没有使用任何reentrant = true模拟方法).还有其他想法吗?

I found a very similar question called "Getting ClassFormatError with EMMA?" but the solution doesn't work for me (I'm not using any reentrant=true mock methods). Any other ideas?

谢谢.

推荐答案

我遇到了同样的问题-这似乎已经为我解决了,希望对其他人也有帮助.

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

如果通过ant运行它,请确保在javac目标的debuglevel参数中没有vars.以下目标将导致错误.

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" />

将其更改为:

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

这可能是JMockit的错误-非常微妙,但要找出答案.

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

这篇关于结合使用JMockit和EMMA的ClassFormatError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 15:50