完全覆盖的代码的EclEmma覆盖率是否可以低于100%? [英] Can fully covered code have an EclEmma coverage rating of less than 100%?

查看:209
本文介绍了完全覆盖的代码的EclEmma覆盖率是否可以低于100%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是编写了一些简单的示例代码来确保正确安装了EclEmma.我没有获得100%的覆盖率,我也不知道为什么.突出显示它与类名有关.这是我的代码,带有相应的JUnit测试,以EclEmma突出显示它的方式:

I just wrote some simple sample code to make sure that I had EclEmma installed correctly. I'm not getting 100% coverage, and I don't understand why. The highlighting implies that it has to do with the class name. Here's my code, with corresponding JUnit tests, the way EclEmma highlighted it:

覆盖率结果表明,即使两个实际方法似乎都被完全覆盖,Arithmetic中的三个指令也没有被击中:

The coverage results show that three instructions in Arithmetic aren't getting hit, even though both actual methods seem to be completely covered:

我已阅读有关基本块覆盖率的EclEmma文档,但是我还是很困惑.我不确定会错过哪些基本块.起初,我以为EclEmma可能只是忽略类的字节码,但是ArithmeticTest似乎处理得很好.

I've read the EclEmma documentation about basic block coverage, but I'm still confused. I'm not sure which basic blocks are being missed. At first, I thought EclEmma might just be ignoring the bytecode for classes, but ArithmeticTest seems to be handled just fine.

我有两个密切相关的问题:

I have two closely related questions:

  1. 这是否表示我安装/配置EclEmma的方式有问题?
  2. 完全覆盖的代码具有很高但不是100%的EMMA覆盖率是正常的/可以接受的,如果是的话,这是如何工作的?

推荐答案

您的代码暗含一个默认构造函数,因为它没有文本块,因此Emma无法正确标记该构造函数.

Your code implies a default constructor, which can't be properly tagged by Emma, because it doesn't have a block of text.

由于在文本块中未正确标记该标记,因此Emma无法将coverage日志记录与文本文件相关联,并且似乎未覆盖某些代码;因为,您运行了一些字节码,但无法注册行日志记录.稍后,当报告元素读取行日志记录时,他们找不到默认构造函数的行号,并且在唯一有意义的地方,即类声明行,突出显示了错误.

Since it is not properly tagged within the block of text, Emma can't associate the coverage logging with the text file, and it looks like some code isn't covered; because, you ran some bytecode, but the line logging couldn't be registered. Later when the reporting element reads the line logging, they can't find the line numbers for the default constructor, and it highlights the error in the only place that sort of makes sense, the class declaration line.

默认构造函数如下

public Arithmetic() {
  super();
}

其中super是隐含的第一条指令,它将构造Object.尽管您可能会忽略它的存在,但编译器会为您添加它.那是您获得"3行"而不是一行的地方.

Where the super is the implied first instruction which will construct Object. While you may omit its presence, the compiler will add it in for you. That's where your get "3 lines" instead of one.

这篇关于完全覆盖的代码的EclEmma覆盖率是否可以低于100%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆