Generating Code Coverage Reports for System Tests with Quarkus

To measure System Test "black box" code coverage for a quarkus app, e.g. this sample code:


@Path("/hello")
public class GreetingResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "Hello RESTEasy";
    }

    @POST
    @Consumes(MediaType.TEXT_PLAIN)
    public void sayHello(String message) {
        System.out.println(message);
    }    
}

add the following dependency to your pom.xml (use the latest jacoco version):

<dependency>
    <groupId>org.jacoco</groupId>
    <artifactId>org.jacoco.agent</artifactId>
    <classifier>runtime</classifier>
    <version>0.8.8</version>
    <scope>test</scope>
</dependency>

Now you build quarkus with the regular maven command: mvn clean package, then launch the app with:

java -javaagent:${HOME}/.m2/repository/org/jacoco/org.jacoco.agent/0.8.8/org.jacoco.agent-0.8.8-runtime.jar=destfile=./target/jacoco.exec,exclclassloader=*QuarkusClassLoader -jar target/quarkus-app/quarkus-run.jar

All interactions with the app are recorded now.

Perform: curl localhost:8080/hello and shutdown quarkus.

To generate a html report, perform: mvn org.jacoco:jacoco-maven-plugin:0.8.8:report

The report is available from: target/site/jacoco/index.html. Because we only executed the @GET / hello() method, our code coverage amounts to 55%.

Element Missed Instructions Cov. Missed Branches Cov. Missed Cxty Missed Lines Missed Methods
Total 4 of 9 55 % 0 of 0 n/a 1 3 2 4 1 3
sayHello(String)
0 % n/a 1 1 2 2 1 1
GreetingResource()
100 % n/a 0 1 0 1 0 1
hello()
100 % n/a 0 1 0 1 0 1

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments
License