gpt4 book ai didi

java - EclEmma(Jacoco) 显示未覆盖的行,即使该行已执行

转载 作者:行者123 更新时间:2023-11-30 10:07:57 24 4
gpt4 key购买 nike

我正在尝试改进代码的行覆盖率。在我调用一个方法的地方执行了一行,该方法又会抛出异常。但是行覆盖显示红色,表示该行未执行。

代码:

1 public void myMethod(SomeService someService){
2 throwException(someService);
3 }

4 public void throwException(SomeService someService){
5 THROW an exception here
6 }

在我的测试类中,我正在准备 SomeService 所需的数据并从上面的代码调用 myMethod。第 2 行显示红色,即使该行被执行并按预期抛出异常。请建议我如何显示覆盖的线路以增加线路覆盖率。

最佳答案

Please use search在发布问题之前,因为这是 widely known JaCoCo 限制在 EclEmma FAQ 中都有描述在JaCoCo FAQ :

Source code lines with exceptions show no coverage. Why?

JaCoCo determines code execution with so called probes. Probes are inserted into the control flow at certain positions. Code is considered as executed when a subsequent probe has been executed. In case of exceptions such a sequence of instructions is aborted somewhere in the middle and the corresponding line of source code is not marked as covered.

换句话说:如果方法调用总是像您的示例中那样抛出异常,那么此方法调用的行将永远不会被标记为完全覆盖,也就是绿色。看到方法调用是否涵盖的唯一方法是执行/测试,当此方法调用不抛出异常时。

关于java - EclEmma(Jacoco) 显示未覆盖的行,即使该行已执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54032393/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com