在此功能中:
private void assertAssurancesMissing(Vote vote) {
assertThrows(
() -> voteManager.showVote(vote.id, "user")
).assertMessageIs("missing assurances");
}
带有lambda函数的第三行在Eclipse的代码覆盖率输出中显示为黄色。同样,showVote()方法也没有覆盖。
包含assertThrows的类的相关部分:
public class ThrowableTester {
private Throwable thrown;
public ThrowableTester assertThrows(Thrower thrower) {
thrown = null;
try {
thrower.throwException();
} catch (Throwable exception) {
thrown = exception;
}
if (thrown == null) {
fail("no exception thrown");
}
return this;
}
}
Thower如下所示:
@FunctionalInterface
public interface Thrower {
void throwException() throws Throwable;
}
我非常确定代码确实在测试中运行,因此必须与lambda函数或@FunctionalInterface一起执行。
如何修改覆盖率报告?