You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When converting an existing testcase that uses PowerMock and EasyMock to use Mockito, I ran into a problem: the test used to use PowerMock.mockStatic(Thread.class) and then do
Thread.sleep(1000);
EasyMock.expectLastCall();
(etc.) to verify that the code paused for the intended time between retry attempts, without the test actually taking many seconds to run. With Mockito (version 5.12.0 on Java 17 for macOs), Mockito.mockStatic(Thread.class) fails, with the following error message (see below for SSCCE):
org.mockito.exceptions.base.MockitoException: It is not possible to mock static methods of java.lang.Thread to avoid interfering with class loading what leads to infinite loops
I can understand that some of the static methods on Thread cannot be safely mocked, but does that also apply to Thread.sleep? Is it possible to somehow do a partial static mock of Thread, so that sleep can be mocked?
The mockito message in the stacktrace have useful information, but it didn't help
The problematic code (if that's possible) is copied here;
Note that some configuration are impossible to mock via Mockito
Provide versions (mockito / jdk / os / any other relevant information)
When converting an existing testcase that uses PowerMock and EasyMock to use Mockito, I ran into a problem: the test used to use
PowerMock.mockStatic(Thread.class)
and then do(etc.) to verify that the code paused for the intended time between retry attempts, without the test actually taking many seconds to run. With Mockito (version 5.12.0 on Java 17 for macOs),
Mockito.mockStatic(Thread.class)
fails, with the following error message (see below for SSCCE):I can understand that some of the static methods on
Thread
cannot be safely mocked, but does that also apply toThread.sleep
? Is it possible to somehow do a partial static mock ofThread
, so thatsleep
can be mocked?Note that some configuration are impossible to mock via Mockito
(same as any question on stackoverflow.com)
Short, self-contained compilable example:
The text was updated successfully, but these errors were encountered: