在 Intelllj idea 中使用“运行代码覆盖率”会出现 ClassFormatError

poe*_*ong 2 junit jmockit intellij-idea jacoco

最近我在intellj idea中使用JMockit和Junit4进行单元测试。当我使用“运行”按钮或“调试”按钮运行测试时,它工作正常。当我尝试使用“运行覆盖率”按钮获取代码覆盖率结果时,它会出现 ClassFormatError。

sun.instrument.InstrumentationImpl.redefineClasses0(本机方法)处的 java.lang.ClassFormatError

仅当我尝试模拟我想要测试的类中的方法时才会发生这种情况,例如

  new Expectations(BaseValidator.class) {
         {
             BaseValidator.isExistAirLineByTwoCode(anyString);
             returns(false, true);
         }
  
   };
Run Code Online (Sandbox Code Playgroud)

我在“BaseValidator”类中测试了另一个方法,该方法调用方法“isExistAirLineByTwoCode”。

不知道这个问题的原因是idea还是jmokit,甚至是junit。顺便说一句,我使用 jacoco 来生成代码覆盖率报告。

我该如何解决这个问题?

Nic*_*len 8

我通过切换到 jacoco runner 找到了解决方法:在菜单中,单击 Run --> Edit Configuration --> 在 JUNIT 类别下选择您的测试

在此输入图像描述

将覆盖跑步者更改为 Jacoco 。