Java - Coverage not reported for test classes run with PowerMock

Problem

Tests that run with PowerMock are not reporting coverage

Cause

Due to an issue with PowerMock till version 1.7.1, tests would fail when using the SeaLights agent. Therefore, by default, the SeaLights agent ignores all classes loaded with the PowerMock class loader and therefore coverage will not be received for these classes.

Solution

If you want to capture coverage for classes run with PowerMock, you need to first upgrade to at least version 1.7.1 of PowerMock.
Then you can remove the SeaLights restriction of PowerMock by passing the Jvm param sl.classLoadersExcluded=none

Doing so depending on your setup:

Jenkins Maven build step:

Under 'Invoke top-level Maven targets with SeaLights Continuous Testing'->SeaLights...->SeaLights Advanced...->'Additional Arguments' add 'sealightsJvmParams=sl.classLoadersExcluded:none'

Maven Automatic configuration 

Edit your JSON file to include a new JvmParams

{ ... "sealightsJvmParams": {"sl.classLoadersExcluded":"none"}, ... }

Maven pom.xml

In the configuration section add an entry for 'classLoadersExcluded' set to none like the following:

<profile> <id>sealights</id> <build> <plugins> <plugin> <groupId>io.sealights.on-premise.agents.plugin</groupId> ... <configuration> ... <classLoadersExcluded>none</classLoadersExcluded> </configuration> <executions> ...

Gradle build.gradle

In the Sealights section add a parameter called 'classLoadersExcluded' set to none like in the following:

allprojects { p -> if(project.hasProperty('sealights')){ apply plugin: 'io.sealights.on-premise.agents.plugin.sealights-gradle-plugin' sealights { ... classLoadersExcluded = "none" } }

Command line (Java CLI)

Pass the -Dsl.classLoadersExcluded=none to the JVM: