Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quarkus code coverage with failsafe #7536

Closed
danielpetisme opened this issue Mar 3, 2020 · 6 comments · Fixed by #17677
Closed

Quarkus code coverage with failsafe #7536

danielpetisme opened this issue Mar 3, 2020 · 6 comments · Fixed by #17677
Labels
kind/question Further information is requested
Milestone

Comments

@danielpetisme
Copy link
Contributor

Not sure if it's a bug or a question so feel free to route me.

I followd the guide explaining how to compute a code coverage with Quarkus
https://quarkus.io/guides/tests-with-coverage

Normally, surefire is used for unit test only where failsafe is the proper plugin for integration testing. So I tried to update the test with failsafe and... it does not work

Here you have a reproducer
https://github.com/danielpetisme/test-jacoco-failsafe
SImply run ./mvnw clean verify and you'll the jacoco file produced for the unit tests but skipped for the integration tests.

I discuss this point with @cescoffier.

While surefire only relies on target/classes to run the tests the jacoco agent can rely on the coverage instrumentation where failsafe use only the jar which 1- is not using the instrumented class 2- you don't want to pollute your final jar with jacoco instrumentation.

Finally I fallback to surefire to run Integration tests but I think it worth a mention in a documentation somewhere.

WDYT?

@danielpetisme danielpetisme added the kind/question Further information is requested label Mar 3, 2020
@stuartwdouglas
Copy link
Member

Do you mean the native image integration tests? I don't think it will ever be possible to get code coverage for native image tests.

@danielpetisme
Copy link
Contributor Author

danielpetisme commented Mar 12, 2020 via email

@stuartwdouglas
Copy link
Member

I think the solution here is to use the agent instead of the instrument task. https://github.com/quarkusio/quarkus/blob/master/build-parent/pom.xml#L677 gives an example for surefire, but I assume it is similar for failsafe.

@pilhuhn
Copy link
Contributor

pilhuhn commented Jun 22, 2020

@danielpetisme Do you have an error message for "not compatible" ?

@danielpetisme
Copy link
Contributor Author

danielpetisme commented Jun 26, 2020 via email

@bvarner
Copy link
Contributor

bvarner commented Jun 2, 2021

Bump on this issue:

I've been trying to get Jacoco to report coverage from failsafe tests, and I cannot get it to do it.
I've set everything up to use the agent, but when the jar is executed by io.quarkus.test.common.JarLauncher the agent is never included.

Looking into the JarLauncher, you can see the following, which corresponds to my logging output from the failsafe plugin:

public void start() throws IOException {

        System.setProperty("test.url", TestHTTPResourceManager.getUri());

        List<String> args = new ArrayList<>();
        args.add("java");
        args.add("-Dquarkus.http.port=" + httpPort);
        args.add("-Dquarkus.http.ssl-port=" + httpsPort);
        // this won't be correct when using the random port but it's really only used by us for the rest client tests
        // in the main module, since those tests hit the application itself
        args.add("-Dtest.url=" + TestHTTPResourceManager.getUri());
        Path logFile = PropertyTestUtil.getLogFilePath();
        args.add("-Dquarkus.log.file.path=" + logFile.toAbsolutePath().toString());
        args.add("-Dquarkus.log.file.enable=true");
        if (profile != null) {
            args.add("-Dquarkus.profile=" + profile);
        }
        for (Map.Entry<String, String> e : systemProps.entrySet()) {
            args.add("-D" + e.getKey() + "=" + e.getValue());
        }
        args.add("-jar");
        args.add(jarPath.toAbsolutePath().toString());

        System.out.println("Executing " + args);

        Files.deleteIfExists(logFile);
        quarkusProcess = LauncherUtil.launchProcess(args);
        ListeningAddress result = waitForCapturedListeningData(quarkusProcess, logFile, jarWaitTime);
        updateConfigForPort(result.getPort());
        isSsl = result.isSsl();
    }

As you can see, there is no way to inject an argline argument.

bvarner added a commit to bvarner/quarkus that referenced this issue Jun 3, 2021
* Fix quarkusio#7536 by adding the ability to specify an argLine property when running tests.

For Example, in a project I'm building:
```
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <systemPropertyVariables>
                                <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                                <maven.home>${maven.home}</maven.home>
                                <quarkus.test.native-image-profile>it</quarkus.test.native-image-profile>
                                <argLine>${argLine}</argLine>
                            </systemPropertyVariables>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
```
bvarner added a commit to bvarner/quarkus that referenced this issue Jun 4, 2021
… documentation, and testing documentation on how to configure.

* Fix quarkusio#7536 by adding the ability to specify an argLine property when running tests.

For Example, in a project I'm building:
```
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <systemPropertyVariables>
                                <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                                <maven.home>${maven.home}</maven.home>
                                <quarkus.test.native-image-profile>it</quarkus.test.native-image-profile>
                                <argLine>${argLine}</argLine>
                            </systemPropertyVariables>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
```
bvarner added a commit to bvarner/quarkus that referenced this issue Jun 8, 2021
… documentation, and testing documentation on how to configure.

* Fix quarkusio#7536 by adding the ability to specify an argLine property when running tests.

For Example, in a project I'm building:
```
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <systemPropertyVariables>
                                <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                                <maven.home>${maven.home}</maven.home>
                                <quarkus.test.native-image-profile>it</quarkus.test.native-image-profile>
                                <argLine>${argLine}</argLine>
                            </systemPropertyVariables>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
```
@quarkus-bot quarkus-bot bot added this to the 2.1 - main milestone Jun 9, 2021
@gsmet gsmet modified the milestones: 2.1 - main, 2.0.0.Final Jun 10, 2021
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jun 10, 2021
… documentation, and testing documentation on how to configure.

* Fix quarkusio#7536 by adding the ability to specify an argLine property when running tests.

For Example, in a project I'm building:
```
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <systemPropertyVariables>
                                <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                                <maven.home>${maven.home}</maven.home>
                                <quarkus.test.native-image-profile>it</quarkus.test.native-image-profile>
                                <argLine>${argLine}</argLine>
                            </systemPropertyVariables>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
```

(cherry picked from commit e6cd85e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants