Code coverage for integration test misses classes

SQ Version - 8.9.6

So, I am trying to run code coverage for our maven multi module project and we have written integration test in a separate module.

We have “mvn verify sonar:sonar -Pcoverage” as part of buildkite pipeline step and it successfully generates the sonarqube report in cloud.

But the report says some of the service layer classes were uncovered with tests even though they are part of the integration test flow.

In the buildkite logs, I can see integration tests being executed.

Is this a normal behavior and does it expect me to write unit tests for the service layer classes as well. We do not have it as of now.

The structure of code is something like this and Integration test class the resource class.

Resource class>Service class

The resource class is showing 100% coverage but service class shows 0%.

I am using Jacoco plugin in the parent pom

 <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <goals>
                            <goal>report-aggregate</goal>
                        </goals>
                        <phase>verify</phase>
                    </execution>
                </executions>
            </plugin>

Hi,

Welcome to the community!

It’s not clear to me what your coverage profile accomplishes, but you need to make sure that you’re feeding into analysis coverage reports that relate to / include all your tests.

 
Ann

The coverage profile pretty much runs the jacoco maven plugin

    <profile>
      <id>coverage</id>
      <!--
          This profile uses jacoco with online instrumentation for unit and integration tests.
      -->
      <build>
        <plugins>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>default-prepare-agent</id>
                <goals>
                  <goal>prepare-agent</goal>
                </goals>
              </execution>
              <execution>
                <id>report</id>
                <goals>
                  <goal>report</goal>
                </goals>
              </execution>
              <execution>
                <id>report-integration</id>
                <goals>
                  <goal>report-integration</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

Hi,

Have you verified that the report that’s produced before analysis includes all your tests/runs/coverage? Because SonarQube only shows you the report data that you feed into it.

 
Ann

I figured it out.

So, my configuration was incorrect.

Just need to follow this structure and pom.

Hope this helps others.

Thanks Ann

1 Like