3

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?

4

2 回答 2

2

我发现 EMMA 的 eclipse 插件有很多 bug,并且和你描述的有类似的经历。最好单独使用 EMMA(如果需要,通过 ANT)。确保始终重新生成 EMMA 生成的元数据文件,以避免合并混淆(我怀疑这是 eclipse 插件的问题)。

于 2008-09-16T14:01:51.010 回答
0

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

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

于 2008-09-11T15:07:52.347 回答