我正在使用Jmockit将我的代码和Eclipse中的Eclemma插件用于代码覆盖。 出于某种原因,我并不能获得报道。其他使用PowerMock的项目,Eclemma显示代码覆盖率很好。但是对于Jmockit来说似乎存在一些问题。
以下是例外情况:
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"
答案 0 :(得分:3)
以下解决方案对我有用:
pom.xml中的依赖项如下所示:
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>