Using Jmockit with Eclemma

谁说我不能喝 提交于 2019-12-11 03:19:30

问题


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.

The following is the exception:

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" 

回答1:


The following solution worked for me:

  1. Upgraded the jmockit version to 1.9. Please note the group id has been changed to "org.jmockit" from "com.googlecode.jmockit" since version 1.9
  2. Ensure you place the jmockit dependency before junit in your pom

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>


来源:https://stackoverflow.com/questions/27316808/using-jmockit-with-eclemma

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