13

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?

Vasily Kabunov
  • 6,511
  • 13
  • 49
  • 53
LottaLava
  • 889
  • 1
  • 9
  • 21
  • 1
    Could you give more details like the verion of Mockito, PowerMock and EclEmma ? – bric3 Mar 16 '12 at 00:12
  • Hey, i´m using the version 2.1.0 of eclEmma, its a bug in that version, in eclEmma 1.5.x it displays fine the tests coverage. – LottaLava Mar 19 '12 at 19:35
  • OK, it seems that _EclEmma_ doesn't use _Emma_ anymore since version 2.x. They are using their own coverage tool which is called JaCoCo. As I don't know the PowerMock version you are using, you should try PowerMock 1.4.11 which includes some fixes related to JaCoCo : http://powermock.googlecode.com/svn/trunk/changelog.txt – bric3 Mar 20 '12 at 09:50
  • Hello, i´m using powermock 1.4.9, i´ll check 1.4.11 against eclEmma 2.1.0, hope its ok. – LottaLava Mar 20 '12 at 13:33
  • Keep me updated, if it's working I'll add a proper answer. – bric3 Mar 20 '12 at 15:25
  • I am running 1.4.12 powermock-api-mockito/powermock-module-junit4 with EclEmma 2.1.2.201205091942 - and I fail to obtain code coverage – Alexey Grigorev Jun 22 '12 at 08:39

4 Answers4

3

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.

Gábor Lipták
  • 9,646
  • 2
  • 59
  • 113
1

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

Damian
  • 437
  • 5
  • 11
1

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.

0

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 :)

Simone Gianni
  • 11,426
  • 40
  • 49