【问题标题】:Using 'Run with code coverage' with Intellj idea gets ClassFormatError使用带有 Intellij 想法的“运行代码覆盖率”得到 ClassFormatError
【发布时间】:2021-11-12 21:11:19
【问题描述】:

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

java.lang.ClassFormatError 在 sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)

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

  new Expectations(BaseValidator.class) {
         {
             BaseValidator.isExistAirLineByTwoCode(anyString);
             returns(false, true);
         }
  
   };

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

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

我该如何解决这个问题?

【问题讨论】:

标签: intellij-idea junit jacoco jmockit


【解决方案1】:

我通过切换到 jacoco runner 找到了解决方法: 在菜单中,单击运行 --> 编辑配置 --> 在 JUNIT 类别下选择您的测试

将coverage runner更改为Jacoco。

【讨论】:

    猜你喜欢
    • 2011-12-17
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-19
    相关资源
    最近更新 更多