poemyong
poemyong

Reputation: 33

Using 'Run with code coverage' with Intellj idea gets ClassFormatError

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?

Upvotes: 2

Views: 2724

Answers (1)

Nick Allen
Nick Allen

Reputation: 1873

I found a workaround by switching to jacoco runner: In the menu, click Run --> Edit Configuration --> choose your test under JUNIT category

enter image description here

change coverage runner to Jacoco .

Upvotes: 10

Related Questions