Description
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 MockitoBeans
in a config class annotated with @TestConfiguration
and import this class using @Import
.
When I define a MockBean instead, 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.