ven*_*esh 24 java junit easymock
We are using EasyMock and PowerMock with JUnit. The coverage tool used is ECLEmma. With EasyMock, it shows the coverage properly in green (as covered). However, for the code that is unit tested with PowerMock, the coverage is shown in red (uncovered). Have read similar questions on the web. However, just wanted to check if there is a solution for this.
Thanks
Venkatesh
Rod*_*yas 14
是的,有一个解决方案:
首先,您必须添加此maven依赖项:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4-rule-agent</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
然后,不要使用这个注释@RunWith(PowerMockRunner.class),只需在Test类中添加一个@Rule,如下所示:
public class Test {
@Rule
public PowerMockRule rule = new PowerMockRule();
Run Code Online (Sandbox Code Playgroud)
您可以在此博客中找到更多内容使EclEmma测试覆盖率与PowerMock配合使用
Nya*_*ope 10
这是一个众所周知的问题:https://github.com/jayway/powermock/issues/422
它已经很长一段时间了,它不会很快修复.
我建议你改用eCobertura.
在我的项目中,这在大多数情况下都有效:
@Rule
public PowerMockRule rule = new PowerMockRule();
static {
PowerMockAgent.initializeIfNeeded();
}
Run Code Online (Sandbox Code Playgroud)
在类路径中@RunWith(PowerMockRunner.class)添加后删除/注释并包含以下导入powermock-module-javaagent-1.6.5.jar:
import org.junit.Rule;
import org.powermock.modules.junit4.rule.PowerMockRule;
import org.powermock.modules.agent.PowerMockAgent;
Run Code Online (Sandbox Code Playgroud)
现在右键单击 - > Coverage As-> Coverage配置并在Arguments中添加以下行:
-ea -noverify -javaagent:path/to/powermock-module-javaagent-1.6.5.jar
Run Code Online (Sandbox Code Playgroud)
单击应用 - >覆盖范围.
另请注意,@Before在这种情况下不起作用,因此您必须在标有@Test方法的方法中添加所有内容@Before.
| 归档时间: |
|
| 查看次数: |
22610 次 |
| 最近记录: |