Skip to content

Support @MockitoBean in @Configuration classes #33934

Closed as not planned
Closed as not planned
@tobias-lippert

Description

@tobias-lippert

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.

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulestatus: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions