PowerMock ECLEmma coverage issue

前端 未结 8 1785
无人共我
无人共我 2020-11-30 09:39


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

相关标签:
8条回答
  • 2020-11-30 10:32

    Yes, there is a solution for this:

    First you will have to add this maven dependency:

    <dependency>
      <groupId>org.powermock</groupId>
      <artifactId>powermock-module-junit4-rule-agent</artifactId>
      <version>1.6.4</version>
      <scope>test</scope>
    </dependency>
    

    Then, instead of using this annotation @RunWith(PowerMockRunner.class), just add a @Rule in the Test class like this:

    public class Test {
    
       @Rule
       public PowerMockRule rule = new PowerMockRule();
    

    you can find more in this blog Make EclEmma test coverage work with PowerMock

    0 讨论(0)
  • 2020-11-30 10:33

    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 for class. This change is only in Eclipse IDE.

    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 讨论(0)
提交回复
热议问题