Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@MockitoBean, @MockitoSpyBean, & @TestBean do not work with @DirtiesContext "before method" modes #33783

Closed
sbrannen opened this issue Oct 24, 2024 · 0 comments
Assignees
Labels
in: test Issues in the test module type: bug A general bug
Milestone

Comments

@sbrannen
Copy link
Member

Overview

@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.

Related Issues

@sbrannen sbrannen added in: test Issues in the test module type: bug A general bug labels Oct 24, 2024
@sbrannen sbrannen added this to the 6.2.0 milestone Oct 24, 2024
@sbrannen sbrannen self-assigned this Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant