gpt4 book ai didi

java - 为什么 EclEmma 不涵盖 syncronized(MyClass.class)?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:21:30 25 4
gpt4 key购买 nike

我正在使用 EclEmma 进行覆盖率分析。

我的 Java 代码包含一个 synchronized(MyClass.class) {} block 。

EclEmma 说它只被部分覆盖,尽管我有一个单元测试,其中一个线程获得访问权限而另一个线程被阻止。

是否可以使用 EclEmma 全面覆盖同步?

我能否以某种方式注释代码以告诉 EclEmma 全面覆盖这一行?

亲切的问候罗杰

最佳答案

我不确定是否有可能获得全面报道,因为 issue 2939804报告:

EMMA always marks synchronized(..) as partially covered

Examples:

synchronized (lock) // partially covered (yellow line in EclEmma)
{
// ...
}
synchronized (this) // partially covered (yellow line in EclEmma)
{
// ...
}

也许不同的工具 ( like Cobertura ) 会产生不同的结果? (我最近没有测试过)。


2012 年 12 月更新(2 年多后):

Nathan D Ryan reports :

synchronized will light to green if the synchronized block contains code that waits on an object monitor, and a test interrupts the waiting thread.

After a little experimentation, I was able to achieve complete coverage of the synchronized line if the synchronized block completed normally and completed abruptly due to an exception.

关于java - 为什么 EclEmma 不涵盖 syncronized(MyClass.class)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3715213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com