为什么 EclEmma 不覆盖 synchronized(MyClass.class)?
我正在使用 EclEmma 进行覆盖率分析。
我的Java代码包含一个synchronized(MyClass.class) {}块。
EclEmma 说它只被部分覆盖,尽管我有一个单元测试,其中一个线程获得访问权限而另一个线程被阻止。
是否可以使用 EclEmma 全面覆盖同步?
我可以以某种方式注释代码来告诉 EclEmma 完全覆盖这一行吗?
亲切的问候 罗杰
I'm using EclEmma for coverage analysis.
My Java code includes a synchronized(MyClass.class) {} block.
EclEmma says it is only partially covered, event though I've got a unit test in which one thread gets access and another thread is blocked.
Is it possible to get full coverage of synchronized using EclEmma?
Can I annotate the code in some way to tell EclEmma to give this line full coverage?
Kind regards
Roger
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定是否可以获得完整的覆盖,因为 问题 2939804 报告:
也许是一个不同的工具 (像 Cobertura) 会产生不同的结果吗? (我最近没有测试过)。
2012 年 12 月更新(两年多后):
Nathan D Ryan 报告:
I am not sure it is possible to get a full coverage, since issue 2939804 reports:
Maybe a different tool (like Cobertura) would yield a different result? (I have not tested it recently).
Update December 2012 (more than 2 years later):
Nathan D Ryan reports:
EclEmma 在下面使用 Jacoco 进行覆盖率分析。
正如 Jacoco 的(当前不存在)JAVAC.SYNC 过滤选项,该行为是为同步块生成的字节代码的结果:
相关的 Jacoco 问题 245 解释了如何触发异常以达到完全覆盖,如果正如 @nathan-ryan 所解释的:
EclEmma uses Jacoco underneath for the coverage analysis.
As explained in Jacoco's (currently non-existing) JAVAC.SYNC filtering option, the behavior is a result of the byte code generated for synchronized blocks:
A related Jacoco issue 245 explains how exceptions can be triggered to reach full coverage, should this be desired, as also explained by @nathan-ryan:
我相信问题是
MyClass.class
,它显然是使用http://emma.sourceforge.net/faq.html#q.fractional.examples
我在第一次通读时错过了这一点。
我将尝试重写我的代码以获得完整的覆盖范围。
/罗杰
I believe the problem is
MyClass.class
which apparently is implemented usinghttp://emma.sourceforge.net/faq.html#q.fractional.examples
I missed that on the first read-through.
I will try to re-write my code to get full coverage.
/Roger