I have a strange behavior of @SpyBean field in my integration tests. For example, I have a few integration tests:
package a;
@SpringBootTest
public class A {
@SpyBean
public MySpyBeanCandidate spyBean;
@Test
public void test1 {
// some work
Mockito.verify(spyBean, Mockito.atLeastOnce()).methodName(eq("String value"), anyString());
}
}
package a;
@SpringBootTest
public class B {
@SpyBean
public MySpyBeanCandidate spyBean;
@Test
public void test2 {
// some work
Mockito.verify(spyBean, Mockito.atLeastOnce()).methodName(eq("String value"), anyString());
}
}
The problem is when I try to execute them separately they executed successfully, but if I'll run them together, in the second test Mockito.verify(..) will throw an exception: Wanted but not invoked
. But I have debugged it and checked that method (methodName
) called correctly. Who knows why this is happening?