quarkusjacocoquarkus-testing

How to set JaCoCo report name with Quarkus?


Currently, when running tests in Quarkus (./mvnw test) the JacoCo report is generated. However, when opening target/jacoco-report/index.html, the h1 tag is filled with the first test class that is run instead of the name of the project.

  1. Is there a reason why artifactId is not used?
  2. How to set the name?

PS: in jacoco.xml it's <report name=""></report>


Solution

  • In Quarkus ecosystem there are two ways to measure code coverage with JaCoCo.

    Using Quarkus JaCoCo extension

    According to the documentation

    This Quarkus extension takes care of everything that would usually be done via the JaCoCo Maven plugin ...

    However it's true it maybe configures JaCoCo a slightly different way then the jacoco-maven-plugin does.

    To customize root node of the report just add this extension to pom.xml

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-jacoco</artifactId>
      <scope>test</scope>
    </dependency>
    

    and set this configuration property in application.properites

    quarkus.jacoco.title=My Awesome Project's coverage report
    

    More configuration options are available here.

    Using jacoco-maven-plugin

    This Maven plugin has a configuration property title to customize the root name of the report.

    According to the goal's documentation

    Default value is : ${project.name}

    And ${project.name} also has default value: ${project.artifactId}.

    So, to customize (override) the root name of the report using jacoco-maven-plugin

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>org.acme</groupId>
        <artifactId>code-with-quarkus</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <name>My Awesome Quarkus App</name>
    </project>
    

    or

    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.12</version>
                <executions>
                   <execution>
                      <id>default-prepare-agent</id>
                      <goals>
                           <goal>prepare-agent</goal>
                      </goals>
                      <configuration>
                        <exclClassLoaders>*QuarkusClassLoader</exclClassLoaders>  
                        <append>true</append>
                      </configuration>
                   </execution>
    
                   <execution>
                      <id>report</id>
                      <goals>
                           <goal>report</goal>
                      </goals>
                      <phase>test</phase>
                      <configuration>
                        <title>Here comes an overridden title</title>
                      </configuration>
                   </execution>
                </executions>
            </plugin>
        </plugins>
    </build>