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
So I've got a some annoying randomly failing tests. They happen a lot on our CI server (quite slow, running red hat) and almost never (1 out of 10000 times) on our workstations (windows, much faster cpus).
I read with the utmost attention the error description:
Bar$$EnhancerByMockitoWithCGLIB$$7e36d32 cannot be returned by getFoo()
getFoo() should return Foo
If you're unsure why you're getting above error read on.
Due to the nature of the syntax above problem might occur because:
This exception might occur in wrongly written multi-threaded tests.
Please refer to Mockito FAQ on limitations of concurrency testing.
A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies -
with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
... But I can't decide which one is applicable here:
Our tests are run by maven surefire, without any threads or forks.
We don't use spies at all.
Our general test structure is :
public class FooTest {
@Mock
private Foo foo;
// ... 10-15 mocked fields generally
@Mock
private Bar bar;
@Before
protected void setup(){
MockitoAnnotations.initMocks(this);
when(foo.getFoo()).thenReturn(foo);
when(bar.getBar()).thenReturn(bar);
// ... 30-40 whens
}
}
Does this ring any bell?
The text was updated successfully, but these errors were encountered:
Hi,
So I've got a some annoying randomly failing tests. They happen a lot on our CI server (quite slow, running red hat) and almost never (1 out of 10000 times) on our workstations (windows, much faster cpus).
I read with the utmost attention the error description:
... But I can't decide which one is applicable here:
Our general test structure is :
Does this ring any bell?
The text was updated successfully, but these errors were encountered: