(Disclaimer: I am not too familiar with the internals of Mockito; I just mentioned it as prominent example. Though it seems to be similar to my usecase, and the use case of other projects.)

How often is appendToBootstrapClassLoaderSearch called in a single run?


My understanding is that it is called once per complete run of the unit tests. However, that also applies to single test method / class runs from the IDE during debugging. So while debugging and writing tests for a project which uses Mockito, that might add up.


 Is the thing that execute the VM with -javaagent in a script or POM configuration?


Generally Mockito is just a test library you declare; it is (to my understanding) agnostic about what build tool is used. Though I assume you are asking in the context of JEP 451 ("Prepare to Disallow the Dynamic Loading of Agents"). For Java 21+ Mockito indeed recommends using `-javaagent` [1].


If the agent is create a temporary JAR file to put on the boot class path then I'm wondering why it can't be given its own directory to do this, and then cleanup after the test run is complete.

I guess that might work, but it would have to be the build tool which sets up that directory and passes it to the agent through `-javaagent`. Maybe that would also allow it to be non-temp (respectively not worry much about concurrency) when using the `target` directory for the project, defined by the build tool. That could indeed be a solution, though I am not sure if that would be desirable for all agent implementations since it would involve (slightly) more configuration work for users.


[1] https://javadoc.io/doc/org.mockito/mockito-core/latest/org.mockito/org/mockito/Mockito.html#mockito-instrumentation

Reply via email to