为什么Cobertura无法报告断言分支路径已被覆盖? [英] Why does Cobertura fail to report assert branch path was covered?
问题描述
在 Cobertura 中,我无法得到它来报告已使用断言语句的条件路径.这是已知限制吗?
In Cobertura, I can not get it to report that the conditional path of an assert statement was taken. Is this a known limitation?
我有一个 JUnit 测试,该测试预期会引发AssertionError并正确通过.问题在于Cobertura报告断言分支未被覆盖.
I have a JUnit test that expects and AssertionError to be thrown, and it passes correctly. The problem is that Cobertura reports that the assert branch was not covered.
经过更多调查,我发现部分分支覆盖范围已被检测到.该行的问题是:
After more investigation, I see that part of the branch coverage is being detected. The line is question is:
assert data != null;
而Cobertura报告的报道范围为:
and Cobertura reports the coverages as:
有条件覆盖率75%(3/4)[每种情况分别为50%,100%].
Conditional coverage 75% (3/4) [each condition 50%, 100%].
Cobertura期望有哪些不同的分支条件?
What are the different branch conditions Cobertura is expecting?
推荐答案
通过两次运行JUnit,我可以获得100%的覆盖率.一次启用断言,一次禁用断言.
I was able to get 100% coverage by running JUnit twice; once with assertions enabled, and once with assertions disabled.
这篇关于为什么Cobertura无法报告断言分支路径已被覆盖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!