mockito / mockito

Most popular Mocking framework for unit tests written in Java
http://mockito.org
MIT License
14.91k stars 2.57k forks source link

Mockito:5.14.2 Warning: Mockito is currently self-attaching... #3512

Open maximkovalenko-hc opened 1 week ago

maximkovalenko-hc commented 1 week ago

Using mockito-core:5.14.2 and spring-boot:3.3.5 shows this warning:

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

image

However the previous versions of mockito (5.13.0, 5.12.0, 5.11.0...) don't have it.

Can we run the latest version of mockito without "Mockito is currently self-attaching..." warning?

More details: mockito-core:5.14.2 mockito-junit-jupiter:5.14.2 spring-boot:3.3.5 Oracle GraalVM 21.0.5+9.1

TimvdLippe commented 1 week ago

Are you sure that your Mockito version resolves to 5.14.2? We haven't made changes in this minor version compared to the previous ones.

maximkovalenko-hc commented 6 days ago

Yes, I can confirm that it's reproduced under the version 5.14.2

jurgis-sipols commented 4 days ago

It might have been done in 5.14.0, PR https://github.com/mockito/mockito/pull/3437/files#diff-dc8b58b0826ca3b51eee39cb3066094b326a7fd2a3d55e492b25e7dea4ab1ad7

Maybe it should not be shown in case -XX:+EnableDynamicAgentLoading is used?

Also, it is worth mentioning that explicit agent solution suggested by https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#0.3 for the Maven builds does not work under this set-up and with Surefire plugin 3.5.2

# Created at 2024-11-20T11:20:16.299
Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'Error occurred during initialization of VM'.

# Created at 2024-11-20T11:20:16.300
Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'agent library failed Agent_OnLoad: instrument'.
raphw commented 4 days ago

I can look into resolving the XX options. However, the warning is there for a reason. Your builds will start failing with Java 22+, so you unfortunately need to adjust your test plugin configuration.

raphw commented 3 days ago

I added a change that would suppress the option if -XX:+EnableDynamicAgentLoading is enabled. The :spotlessApply target seems to have disappeared, @TimvdLippe?

TimvdLippe commented 3 days ago

Might have been broken by the recent build refactorings @bric3 ?

bric3 commented 3 days ago

Hi, not broken but moved! In gradle terms : is the root project, and mockito core code base used to be in the root project, now it's in mockito-core which is referred to as :mockito-core. And since the root project has no more code there's not anymore spotless tasks. In practice that means:

raphw commented 2 days ago

Indeed, thanks. I just ran a command from my console history and fell over that.