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
@MockitoBean, @MockitoSpyBean, and @TestBean currently do not work with @DirtiesContext modes DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD and MethodMode.BEFORE_METHOD.
Attempting to use one of those "before method" modes will result in a corresponding @MockitoBean, @MockitoSpyBean, or @TestBean field containing a bean instance from a closed ApplicationContext. In addition, any other beans in the current, live ApplicationContext will reference different instances of those @MockitoBean, @MockitoSpyBean, and @TestBean beans.
The reason is that the BeanOverrideTestExecutionListener is currently assigned an order of LOWEST_PRECEDENCE - 50; whereas, in order for things to work properly, it must be assigned an order greater than the DirtiesContextBeforeModesTestExecutionListener and less than the DependencyInjectionTestExecutionListener.
Overview
@MockitoBean
,@MockitoSpyBean
, and@TestBean
currently do not work with@DirtiesContext
modesDirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD
andMethodMode.BEFORE_METHOD
.Attempting to use one of those "before method" modes will result in a corresponding
@MockitoBean
,@MockitoSpyBean
, or@TestBean
field containing a bean instance from a closedApplicationContext
. In addition, any other beans in the current, liveApplicationContext
will reference different instances of those@MockitoBean
,@MockitoSpyBean
, and@TestBean
beans.The reason is that the
BeanOverrideTestExecutionListener
is currently assigned an order ofLOWEST_PRECEDENCE - 50
; whereas, in order for things to work properly, it must be assigned an order greater than theDirtiesContextBeforeModesTestExecutionListener
and less than theDependencyInjectionTestExecutionListener
.Related Issues
The text was updated successfully, but these errors were encountered: