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
Hi, I ran into the problem of hanging tests when they have mock WeakReference.
The test code looks something like this:
classFooTest {
@Test
funtest() {
val weakReference =Mockito.mock(WeakReference::class.java) asWeakReference<Bar>
val bar =Mockito.mock(Bar::class.java)
Mockito.doReturn(bar).`when`(weakReference).get()
val foo =Foo(weakReference)
val consumedBar = foo.get()
Mockito.verify(foo.get())
Assertions.assertEquals(consumedBar, bar)
}
}
Is there any way around this, or is it impossible?
Stacktrace
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "/127.0.0.1:52766 to /127.0.0.1:52765 workers Thread 2"
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "Test worker"
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "process reaper"
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "/127.0.0.1:52766 to /127.0.0.1:52765 workers Thread 4"
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "process reaper"
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "/127.0.0.1:52766 to /127.0.0.1:52765 workers Thread 5"
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "process reaper"
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "/127.0.0.1:52766 to /127.0.0.1:52765 workers Thread 6"
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "process reaper"
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "/127.0.0.1:52766 to /127.0.0.1:52765 workers Thread 7"
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "process reaper"
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "/127.0.0.1:52766 to /127.0.0.1:52765 workers Thread 8"
Versions
Mockito core version = 3.12.4
Mockito inline version = 3.12.4
Junit5 version = 1.7.20
OS Version = macOS:12.5.1:21G83
JDK version = openjdk 15.0.2 2021-01-19
OpenJDK Runtime Environment Corretto-15.0.2.7.1 (build 15.0.2+7)
OpenJDK 64-Bit Server VM Corretto-15.0.2.7.1 (build 15.0.2+7, mixed mode, sharing)
Notes
The error cannot be reproduced without connecting mockito-inline, perhaps the problem is org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.
Unfortunately, WeakReference is one of the classes that Mockito relies on internally for its behavior. Stubbing WeakReference will therefore lead to undefined behavior. Additionally, it is advised not to mock classes you don't own: https://github.com/mockito/mockito/wiki/How-to-write-good-tests#dont-mock-a-type-you-dont-own We are working on improving the user experience by working on a DoNotMock feature to avoid mocking classes/methods that are known to crash Mockito internals (#1833). Therefore, I am closing this as "Infeasible". Apologies for the uninformative exception that is thrown.
Hi, I ran into the problem of hanging tests when they have mock WeakReference.
The test code looks something like this:
Is there any way around this, or is it impossible?
Stacktrace
Versions
Notes
The error cannot be reproduced without connecting mockito-inline, perhaps the problem is org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.
Full sample
The text was updated successfully, but these errors were encountered: