本文介绍了将Jmockit与Eclemma结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Jmockit将我的代码和Eclipse中的Eclemma插件结合起来以进行代码覆盖.由于某些原因,我不希望获得这份报道.其他使用PowerMock,Eclemma的项目显示出很好的代码覆盖率.但是使用Jmockit似乎有一些问题.
I am using Jmockit to junit my code and Eclemma plugin in Eclipse for code coverage.For some reason I am not abe to get the coverage. Other project which uses PowerMock, Eclemma shows code coverage fine. But with Jmockit there seems to be some problem.
以下是例外:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:323)
at sun.instrument.InstrumentationImpl.loadClassAndCallAgentmain(InstrumentationImpl.java:348)
Caused by: java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the schema (add/remove fields)
at sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)
at sun.instrument.InstrumentationImpl.redefineClasses(InstrumentationImpl.java:150)
at mockit.internal.RedefinitionEngine.redefineMethods(RedefinitionEngine.java:245)
at mockit.internal.RedefinitionEngine.redefineMethods(RedefinitionEngine.java:239)
at mockit.internal.RedefinitionEngine.redefineMethods(RedefinitionEngine.java:166)
at mockit.internal.RedefinitionEngine.setUpStartupMock(RedefinitionEngine.java:132)
at mockit.internal.startup.JMockitInitialization.setUpInternalStartupMock(JMockitInitialization.java:55)
at mockit.internal.startup.JMockitInitialization.loadInternalStartupMocksForJUnitIntegration(JMockitInitialization.java:38)
at mockit.internal.startup.JMockitInitialization.initialize(JMockitInitialization.java:25)
at mockit.internal.startup.Startup.initialize(Startup.java:68)
at mockit.internal.startup.Startup.agentmain(Startup.java:62)
... 6 more
5 Dec, 2014 6:40:44 PM com.nn.ood.common.props.PropertyReader
WARNING: No configuration file(s) found for application ca and layer be.
Agent failed to start!
Exception in thread "Attach Listener"
推荐答案
以下解决方案对我有用:
The following solution worked for me:
- 将jmockit版本升级到1.9.请注意,群组ID已从"com.googlecode.jmockit"更改为"org.jmockit",因为1.9版
- 确保在pom中将jmockit依赖项放在junit之前
- Upgraded the jmockit version to 1.9. Please note the group id hasbeen changed to "org.jmockit" from "com.googlecode.jmockit" sinceversion 1.9
- Ensure you place the jmockit dependency before junit in your pom
pom.xml中的依赖项如下所示:
The dependencies in pom.xml looks like this:
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
这篇关于将Jmockit与Eclemma结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!