Recently I use JMockit and Junit4 for unit tests in intellj idea. When I run my test using the 'Run' button or the 'debug' button, it works fine. When I try to get my code coverage result using the 'Run with coverage' button, it gets ClassFormatError.
java.lang.ClassFormatError at sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)
It happens only when I try to mock a method in the class which I want to test, like
new Expectations(BaseValidator.class) {
{
BaseValidator.isExistAirLineByTwoCode(anyString);
returns(false, true);
}
};
I test another method in class 'BaseValidator' which calls the method 'isExistAirLineByTwoCode'.
I don't know if the cause of this problem is from idea or jmokit, even junit. By the way, I use jacoco for code coverage reports.
How can I fix this problem?
I found a workaround by switching to jacoco runner: In the menu, click Run --> Edit Configuration --> choose your test under JUNIT category
change coverage runner to Jacoco .