quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.83k stars 2.69k forks source link

Quarkus:test shows warning about Mockito inline mocking #44446

Open Postremus opened 1 week ago

Postremus commented 1 week ago

Description

After upgrading to quarkus 3.16.2, I am greeted by this warning from mockito during my quarkus:test run:

2024-11-12 16:28:41,271 INFO [io.quarkus] (main) Installed features: [agroal, awt, cdi, config-yaml, cxf, hibernate-orm, hibernate-validator, jdbc-postgresql, liquibase, messaging, messaging-rabbitmq, narayana-jta, poi, quartz, rest, rest-client, rest-client-jackson, rest-jackson, scheduler, smallrye-context-propagation, smallrye-fault-tolerance, smallrye-health, smallrye-metrics, smallrye-openapi, swagger-ui, vertx] Mockito is currently self-attaching to enable the inline-mock-maker. This will no longer work in future releases of the JDK. Please add Mockito as an agent to your build what is described in Mockito's documentation: https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#0.3

I am running on java 21.

Can you please either suppress this warning for now, or automatically fix it?

Implementation ideas

No response

quarkus-bot[bot] commented 1 week ago

/cc @geoand (testing)

geoand commented 1 week ago

Unfortunately there is nothing we can do at this point to silence the warning without actually addressing the issue at hand (i.e. configuring the mockito agent on the command line). If you want to spend half your day reading up on why the ecosystem arrived at this state, take a look here, it's got tons of great information.

For now, what I propose is doing the following:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>properties</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Then configure maven-surefire-plugin like so:

            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <configuration>
                    <systemPropertyVariables>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <maven.home>${maven.home}</maven.home>
                    </systemPropertyVariables>
                    <argLine>-javaagent:${org.mockito:mockito-core:jar}</argLine>
                </configuration>
            </plugin>

Note that if you have any plugin that alters the state of the arg line created by surefire (like Jacoco), you need to instead use:

            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <configuration>
                    <systemPropertyVariables>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <maven.home>${maven.home}</maven.home>
                    </systemPropertyVariables>
                    <argLine>@{argLine} -javaagent:${org.mockito:mockito-core:jar}</argLine>
                </configuration>
            </plugin>

What we should probably to do on our side @ia3andy (cc @cescoffier @gsmet) is to have our code.quarkus.io templates (and perhaps our quarkus update recipes) create the configuration I mentioned above when quarkus-junit5-mockito is added as a dependency.

Mockito itself has some docs about this.

holly-cummins commented 1 week ago

Having the quickstart and codestart templates and quarkus update do the tedious maven config is a super idea.