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 in TestConfiguration is not picked up whereas MockBean is #33934

Open
tobias-lippert opened this issue Nov 21, 2024 · 0 comments
Open
Labels
status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@tobias-lippert
Copy link

tobias-lippert commented Nov 21, 2024

Versions
Spring Boot 3.4.0
Spring Framework 6.2.0

Hi Spring team,

While upgrading our apps to Spring Boot 3.4.0, I've encountered that some of our tests don't start because the application context cannot be created due to a missing bean dependency that should exist as mocked bean.

We define some mocks in a config class annotated with @TestConfiguration and import this class using @Import.
When I define a MockBean, the tests succeed.

You can find an example that reproduces the behavior here: https://github.com/tobias-lippert/spring-mockitobean-test-configuration-import-bug
The test passes on the branch mockbean-working and fails on the branch mockitobean-not-working.

I couldn't find anything in the docs pointing out that this should no longer work. If this is not a bug, but intended behavior please advise how to fix this.
The easiest, but not the prettiest workaround I've found is getting rid of the separate TestConfigurations and placing all MockitoBeans in the actual test class.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

2 participants