I met a problem of using EclEmma plugin in Eclipse.
It doesn't show code coverage when I use annotation @RunWith
passing (PowerMockRunner.class)
as an argument. In case of using (MockitoJUnitRunner.class)
everything is fine.
Waiting for your suggestions? :)
问题:
回答1:
This is a known problem with Eclemma (JaCoCo). Basically both libraries modify byte code but Mockito modifies it during runtime which produces a different binary .class file. JaCoCo apparently uses keeps track of the classes it's watching via a hashMap whose hashcode is derived by the class definition so the hashcode will be different after Mockito modifies the class so JaCoco can't find the class in it's internal Maps anymore.
Discussed in more detail:
Why EclEmma doesn't coverage code with tests with @RunWith(PowerMockRunner.class)
Emma code coverage with JUnit and Powermock
http://code.google.com/p/powermock/issues/detail?id=402
回答2:
Per this link last update, updating EclEmma plugin (by Uninstalling and Reinstalling) along with latest PowerMock and Mockito JARs in Eclipse (3.7) resolved the issue.
This change log confirms that.
回答3:
Powermock works well with Eclemma 1.5.3; but doesn't work with latest Eclemma 3.0.0 !!
Eclipse - Kepler Service release 2 JUnit4 PowerMockito2 - 1.7.0. Eclemma 1.5.3
The below given steps are working and I am able to see non-zero coverage % on running junit tests.
- Download eclemma-1.5.3.zip from http://www.eclemma.org/download.html
- Extract the contents to a local folder (eclemma-1.5.3)
- Add this path to Menu bar : Window -> Preferences -> Install/Update -> Available Software Sites
- Help -> Install New Software -> in "Work with" drop down, select the new entry (added in prev. step)
- Uncheck the check boxes one after another then the "Eclemma Coverage" plugin options will be shown. Eclemma Coverage option will be shown in selection window.
- Proceed to next and complete...
Enjoy !!!
回答4:
EclEmma modifies bytecode to detect code coverage as PowerMock does to allow you to run an inaccessible code. Both changes are incompatible
The solution is to use a runner offered by PowerMock which workaround that incompatibility
http://www.notonlyanecmplace.com/make-eclemma-test-coverage-work-with-powermock/