Skip to content

Provide a safe way to override and mock beans in the TestContext framework #29917

@mwisnicki

Description

@mwisnicki

Overriding beans in testing is commonly needed yet current approach is unnecessarily complicated and at the same time limited and very error prone (allow-bean-definition-overriding will hide other issues). For example see spring-projects/spring-boot#30513

It would be great if there was a single annotation that allowed overriding single bean in testing, e.g.:

@SpringBootTest
class SomeTest {

  @Bean @TestOverride
  MyBean myBean() { return new MyBean() }

}

Even better if it could be relaxed to support field instead of method.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions