当方法内的代码被 emma 覆盖时,为什么方法调用显示为未覆盖?
我正在编写一个单元测试来检查私有方法是否会关闭流。
单元测试调用 methodB 并且变量 Something 为 null
单元测试不会模拟测试中的类
私有方法位于我正在调用的公共方法内。
在 eclipse 中使用 emma (通过 eclemma 插件),即使方法中的代码是
例如,
public methodA(){
if (something==null) {
methodB(); //Not displayed as covered
}
}
private methodB(){
lineCoveredByTest; //displayed as covered
}
方法调用也显示为未被覆盖,为什么方法调用不会突出显示为被覆盖?
I am writing a unit test to check that a private method will close a stream.
The unit test calls methodB and the variable something is null
The unit test doesn't mock the class on test
The private method is within a public method that I am calling.
Using emma in eclipse (via the eclemma plugin) the method call is displayed as not being covered even though the code within the method is
e.g
public methodA(){
if (something==null) {
methodB(); //Not displayed as covered
}
}
private methodB(){
lineCoveredByTest; //displayed as covered
}
Why would the method call not be highlighted as being covered?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设当您说“单元测试调用
methodB()
”时,您的意思是不是直接调用methodA()
。那么,是否有可能
methodB()
在其他地方被另一个单元测试或methodC()
调用?I assume when you say 'the unit test calls
methodB()
', you mean not directly and viamethodA()
.So, is it possible
methodB()
is being called elsewhere, by another unit test ormethodC()
maybe?我发现 EMMA 的 eclipse 插件有很多 bug,并且与您描述的经历类似。 最好单独使用 EMMA(如果需要,通过 ANT)。 确保始终重新生成 EMMA 生成的元数据文件,以避免合并混乱(我怀疑这是 eclipse 插件的问题)。
I have found that the eclipse plugin for EMMA is quite buggy, and have had similar experiences to the one you describe. Better to just use EMMA on its own (via ANT if required). Make sure you always regenerate the metadata files produced by EMMA, to avoid merging confusion (which I suspect is the problem with the eclipse plugin).