Using Jmockit with Eclemma

5.4k views Asked by At

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

There are 1 answers

0
as.tek On BEST ANSWER

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>