如何忽略 java 核心断言的覆盖范围,Eclipse Eclemma

How to Ignore coverage for java core assertions, Eclipse Eclemma

我对 Eclemma 插件配置有疑问: 在生产代码中,我有很多 java 核心断言,例如:

assert arr.size() == 2 : "message";

当我在我的单元测试中 运行 Eclemma 时,它显示低覆盖率,因为断言上有黄色标记。 放置断言的想法是不要有可能以断言的否定案例结束(它永远不应该发生!),它们只是代码质量保护,仅此而已。 但另一方面,Eclemma 认为这些否定案例没有被声明的分支覆盖(这是 marazmatic :)),因此它将它们标记为黄色。

所以,问题是: 如何配置 Eclemma 以忽略覆盖率报告中的 "assert" 代码行?

EclEmma - 是基于 Java 代码覆盖库的 Eclipse 插件,名为 JaCoCo. JaCoCo performs analysis of bytecode, and unfortunately doesn't have yet filtering for the bytecode that compiler generates for assert