PowerMock ECLEmma coverage issue

前端 未结 8 1789
无人共我
无人共我 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:10

    This has worked in most cases in my project:

    @Rule
    public PowerMockRule rule = new PowerMockRule();
    static {
        PowerMockAgent.initializeIfNeeded();
    }
    

    Remove/Comment @RunWith(PowerMockRunner.class) & include following imports after adding powermock-module-javaagent-1.6.5.jar in your classpath:

    import org.junit.Rule;
    import org.powermock.modules.junit4.rule.PowerMockRule;
    import org.powermock.modules.agent.PowerMockAgent;
    

    Now right click->Coverage As->Coverage Configurations and add following lines in Arguments:

    -ea -noverify -javaagent:path/to/powermock-module-javaagent-1.6.5.jar
    

    Click Apply->Coverage.

    Also note that @Before would not work in this case so you have to add all the stuffs in the methods marked with @Test from the method marked with @Before.

提交回复
热议问题