0

I am using jacoco gradle plugin. My Unit test cases are failing and getting below exception. I searched in form but didnt get answer. Same test cases are working fine with maven (jacoco-maven) plugin.

ava.lang.UnsupportedOperationException: class redefinition failed: attempted to change the schema (add/remove fields) at sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)

I am using jmockit 1.12 and jacoco toolVersion = '0.7.1.201405082137'

1
  • What version of JMockit library are you using during Gradle build/test? If it's not compatible with the jacoco version then it cries with the above message. Commented Aug 26, 2015 at 16:57

2 Answers 2

2

For me, the root cause is that I didn't put jmockit dependency before junit dependency. So please ensure you have dependencies like the following:

testCompile 'org.jmockit:jmockit:1.29'
testCompile 'junit:junit:4.12'
Sign up to request clarification or add additional context in comments.

Comments

1

Both Jmockit and Jacoco instruments the class files. Jmockit does it first during the build process and when jacoco tries the same (later in the process) it says "oh oh, can't instrument an already instrumented class file". This issue happened with older versions of jacoco and jmockit. To see this error, enable --stacktrace option during Gradle build or --debug.

Now, using the latest jacoco and jmockit versions, we can solve this issue easily.

If you use jacoco (or use the latest one here):

toolVersion="0.7.1.201405082137"

or

toolVersion="0.7.2.201409121644"

or

toolVersion="0.7.5.201505241946"

See this: changes that went in 0.7.1 version.

For JMockit, you have to use jmockit version: 1.8 at least or later (1.9 to 1.13).

org.jmockit:jmockit:1.8

See this: changes that went under 1.8 version: http://jmockit.github.io/changes.html

I see the latest jmockit version out there is now 1.19, so use these two in Gradle with versions which are compatible and support each other.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.