当方法内的代码被 emma 覆盖时,为什么方法调用显示为未覆盖?

发布于 2024-07-04 06:39:05 字数 429 浏览 15 评论 0原文

我正在编写一个单元测试来检查私有方法是否会关闭流。

单元测试调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

琉璃繁缕 2024-07-11 06:39:06

我假设当您说“单元测试调用 methodB()”时,您的意思是不是直接调用 methodA()

那么,是否有可能 methodB() 在其他地方被另一个单元测试或 methodC() 调用?

I assume when you say 'the unit test calls methodB()', you mean not directly and via methodA().

So, is it possible methodB() is being called elsewhere, by another unit test or methodC() maybe?

掩耳倾听 2024-07-11 06:39:05

我发现 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文