问题描述
我试图使用Eclipse和EclEmma来获取我的代码覆盖率。我的测试使用JUnit 4,我有一些测试看起来像这个:
@Test(expected = IllegalArgumentException.class)
public void createTime_withInvalidMinuteUnder0_throws(){
/ /排列
...
// Act
触发IllegalArgumentException的东西
}
EclEmma表示测试失败,因为有一个IllegalArgumentException被抛出。所以它会丢弃我的代码覆盖率指标,即使它应该抛出一些东西。有没有可以让它看到JUnit预期的异常标记?
编辑:我已经发现,如果将throw添加到测试声明中,它的作品!
不,没有办法让EclEmma注意到预期
子句。他们承认此事实。
我个人不用担心太多了。测试用例的覆盖是EclEmma可以告诉你的最不重要的事情;我总是完全忽视这些指标,并专注于我的生产代码的覆盖范围。
I'm trying to get my code coverage in java, using Eclipse and EclEmma.
My tests are using JUnit 4 and I've got some tests looking like this :
@Test(expected = IllegalArgumentException.class)
public void createTime_withInvalidMinuteUnder0_throws(){
//Arrange
...
//Act
Something triggering IllegalArgumentException Here
}
And EclEmma says that the test fails because there's an IllegalArgumentException being thrown. So it drops my code coverage indicator even though it's supposed to throw something. Is there an option to make it see that JUnit expected exception tag ?
edit: I've found out that if you add the throw to the declaration of the test aswell, it works!
No, there is no way to get EclEmma to notice the expected
clause. They acknowledge this fact here.
Personally, I wouldn't worry too much about it. Coverage of test cases is the least interesting thing EclEmma can tell you; I always completely ignore those metrics and focus on the coverage of my production code.
这篇关于Java中的代码覆盖与EclEmma不扫描预期的异常方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!