/
Java - Coverage not reported for test classes run with PowerMock

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:

Related articles







Related content

Using Java Agents - Installing the Coverage Listener as a JVM Java Agent
Using Java Agents - Installing the Coverage Listener as a JVM Java Agent
Read with this
SeaLights Jenkins plugin for Maven Project job - Scanning Builds and running Unit Tests using Maven
SeaLights Jenkins plugin for Maven Project job - Scanning Builds and running Unit Tests using Maven
More like this
Installing our agents - Typical Setup
Installing our agents - Typical Setup
Read with this
SeaLights Jenkins Plugin - Running tests using Maven
SeaLights Jenkins Plugin - Running tests using Maven
More like this
Scanning Builds using the SeaLights Maven plugin
Scanning Builds using the SeaLights Maven plugin
Read with this
SeaLights Jenkins plugin - Scanning Builds and running Unit Tests using Maven
SeaLights Jenkins plugin - Scanning Builds and running Unit Tests using Maven
More like this