quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

Jacoco coverage across jUnit and @QuarkusTest not working

Open HerrDerb opened this issue 3 years ago • 2 comments
trafficstars

Describe the bug

Wen having plain jUnit tests and @QuarkusTests side by side, the jacoco coverage is missing the coverage from the jUnit test. This behaviour still exists after applying the configuration suggested by quarkus: https://quarkus.io/guides/tests-with-coverage#coverage-for-tests-not-using-quarkustest

Expected behavior

The jacoco coverage report should respect the jUnit test and the @QarkusTest coverage

Actual behavior

Only the @Quarkus coverage is included in the jacoco coverage report

How to Reproduce?

Sample repository: https://github.com/HerrDerb/quarkus-jacoco-issue

  1. Run ./mvnw clean install
  2. Open /target/jacoco-report/org.acme/index.html

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

HerrDerb avatar Aug 05 '22 07:08 HerrDerb

Any news about this issue?

Is it recomendet to only use @QuarkusTest tests for beans and not normal unit tests if possible?

joggeli34 avatar Sep 02 '22 11:09 joggeli34

I was experiencing this issue.

Changing the jacoco-maven-plugin version to be the same as the jacoco version imported by quarkus, seems to have fixed it.

Unfortunately, it seems this has to be manually synced. Maybe it helps.

darraghc345 avatar Sep 19 '22 16:09 darraghc345

I've been facing the same problem about this topic in my project. I have the 0.8.7 jacoco version set in my pom, but the issue still happening.

ghost avatar Sep 22 '22 15:09 ghost

I'm experiencing the same issue as @HerrDerb . Unfortunately, the workaround proposed by @darraghc345 does not seem to help in my case. I'm using Quarkus 2.13.0 and JaCoCo 0.8.8.

markuseckstein avatar Oct 04 '22 11:10 markuseckstein

@HerrDerb I generated jacoco report based on your sample project, I got both coverage (junit + quarkus) :

image

GreetingService = Quarkus ByeService = jUnit

GChapel avatar Oct 30 '22 20:10 GChapel

I must have had some wierd configuration. In our new project it also does work. I'll close this issue. If it does not work, it's most probalby because of a bad configuration.

HerrDerb avatar Oct 31 '22 08:10 HerrDerb

I know that this issue is already closed. But I just experienced the exact same problem.

Quarkus 2.14.2, Jacoco 0.8.8.

None of the advice given here helped for me.

In the end, I found that, at the beginning of the integration tests, Quarkus threw away target/jacoco-quarkus.exec and recreated it from scratch. So, all the coverage from the unit tests was lost by design.

What helped for me was adding quarkus.jacoco.reuse-data-file to my application.yml and setting it to true (defaults to false).

I guess this hint should be added to the Quarkus documentation that most of the people relied on before coming here.

mueihn avatar Dec 01 '22 22:12 mueihn

I am also facing the same issue but its intermittent. Like on one run it shows proper coverage but on the next run it doesn't show unit test coverage. None of the above shared solution have worked for me. cc: @cescoffier

ashutoshk2206 avatar Aug 07 '23 13:08 ashutoshk2206

Same issue. Using quarkus 2.16.

gitkeerthi avatar Oct 05 '23 09:10 gitkeerthi

I've fixed it like this in my pom.xml

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${versions.jacoco}</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <exclClassLoaders>*QuarkusClassLoader</exclClassLoaders>
                            <destFile>${project.build.directory}/jacoco-quarkus.exec</destFile>  ----> this is the fix
                            <append>true</append>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-code-coverage-report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Really, strange that I had to change that line, since this pom.xml was a copy/paste from another project where the unit tests do get covered by Jacoco. And there the line was ${project.build.directory}/jacoco.exec.

And btw, I'm using Quarkus 3.2.8.Final & jacoco 0.8.11.

Serkan80 avatar Nov 10 '23 09:11 Serkan80

I've fixed it like this in my pom.xml

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${versions.jacoco}</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <exclClassLoaders>*QuarkusClassLoader</exclClassLoaders>
                            <destFile>${project.build.directory}/jacoco-quarkus.exec</destFile>  ----> this is the fix
                            <append>true</append>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-code-coverage-report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Really, strange that I had to change that line, since this pom.xml was a copy/paste from another project where the unit tests do get covered by Jacoco. And there the line was ${project.build.directory}/jacoco.exec.

And btw, I'm using Quarkus 3.2.8.Final & jacoco 0.8.11.

Hey mate can you please share that are you able to generate the unit and integration test report separately, if so can you please provide the GitHub link for the same, I am struggling to find these same problem

iamgul avatar Dec 03 '23 17:12 iamgul

I've fixed it like this in my pom.xml

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${versions.jacoco}</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <exclClassLoaders>*QuarkusClassLoader</exclClassLoaders>
                            <destFile>${project.build.directory}/jacoco-quarkus.exec</destFile>  ----> this is the fix
                            <append>true</append>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-code-coverage-report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Really, strange that I had to change that line, since this pom.xml was a copy/paste from another project where the unit tests do get covered by Jacoco. And there the line was ${project.build.directory}/jacoco.exec.

And btw, I'm using Quarkus 3.2.8.Final & jacoco 0.8.11.

Didn't work here :(

otavioprado avatar Jan 09 '24 19:01 otavioprado