Why EclEmma doesn't coverage code with tests w

2020-06-12 04:54发布

I am using EclEmma with Eclipse to help me to know where is missing code tests in my project, but all tests with @RunWith(PowerMockRunner.class) are not called and thus not tested.

I´m using JUnit 4.8.1 with Mockito.

What could it be?

4条回答
smile是对你的礼貌
2楼-- · 2020-06-12 05:33

Here you can find example that works and may help you solve this problem https://github.com/Godin/jacoco-experiments

use mvn clean package to see jacoco report

查看更多
看我几分像从前
3楼-- · 2020-06-12 05:36

AFAIK eclEmma, as well as many other coverage systems, modify your .class files to add coverage instructions. Most of these tools do that at "compile time", not at run time.

PowerMock instead, as well as AspectJ LTW and many other systems, manipulate the same bytecode but at "run time":

PowerMock is a framework that extend other mock libraries such as EasyMock with more powerful capabilities. PowerMock uses a custom classloader and bytecode manipulation to enable mocking of static methods, constructors, final classes and methods, private methods, removal of static initializers and more.

I have a similar problem with both eclEmma (various versions) and Cobertura in combination with AspectJ LTW, cause when the runtime modification of .class files happen, it somehow corrupts the modification done previously by the coverage tool.

I don't have yet found a solution, but at least found the symptom.

The right solution would be to debug PowerMock instrumentation and find out where and how it breaks coverage tools. It's quite a problem, for a testing tool, to break coverage tools, since the two are quite often used together :)

查看更多
beautiful°
4楼-- · 2020-06-12 05:37

Its a known bug reported for both parties:

http://code.google.com/p/powermock/issues/detail?id=402 https://github.com/jacoco/eclemma/issues/15#issuecomment-9565210

eCoberture seems however to provide correct coverage. The only problem, that it seems not to be maintained anymore, and you cannot remove the highlights im Eclipse Juno.

查看更多
Lonely孤独者°
5楼-- · 2020-06-12 05:44

We have a static classes to mock. With mocking static classes, eclEmma code coverage plugin is not working in Eclipse. So what we did is, so placed @RunWith(JUnit4.class) (Instead of @RunWith(PowerMockRunner.class) ) before class and placed following lines inside class

static {
PowerMockAgent.initializeIfNeeded();
}

@Rule
public PowerMockRule rule = new PowerMockRule();

Compiled the class and ran the test class. Code coverage is working fine for class. This change is only to run eclEmma plugin in Eclipse IDE with no issues.

After writing test cases, we reverted code back to normal. Placed @RunWith(PowerMockRunner.class) instead of @RunWith(JUnit4.class) and commented above static code and powermockrule lines.

查看更多
登录 后发表回答