Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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 .

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.