Search code examples
unit-testingkotlintestingpowermock

PowerMockito whenNew without PrepareForTest


Jacoco does not cover tests using @PrepareForTest(Class.class).

I need to use PowerMockito whenNew method, but it does not work without the PrepareForTest annotation.

Is there any workaround for this issue?


Solution

  • JaCoCo could work in two mods:

    • collecting coverage with java agent
    • offline instrumentation

    If you'd like to collect coverage from PowerMock test then you should use offline instrumentation.

    Here working example for Gradle: https://github.com/SurpSG/jacoco-offline-instrumentation