I am using jacoco offline instumentation but dont see code coverage in the report for private function- getName(). When i run the jacoco reports, the coverage for getName() is 0%. Is there something wrong with the Junit or the configurations?
Below is the main class
public class CheckNameHandler implements RequestHandler<S3Event, Void> {
@Override
public Void handleRequest(S3Event s3Event, Context context) {
String name = getName();
return null;
}
private String getName(){
return "test";
}
}
Below is the test class
public class CheckNameHandlerTest {
@Test
public void handlerSuccessTest() {
CheckNameHandler spyCheckNameHandler = PowerMockito.spy(new CheckNameHandler());
PowerMockito.doReturn("test").when(spyCheckNameHandler, "getName");
S3Event s3Event = .......;
Context context = .......;
spyCheckNameHandler.handleRequest(s3Event, context);
}
Below is the pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.8</version>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/coverage.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>${project.build.directory}/coverage.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
And below are the dependencies
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>1.7.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.7.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>0.7.8</version>
<scope>test</scope>
</dependency>