Skip to content

@MockBean fields are not reset for JUnit 5 @Nested tests using @WebMvcTest #23984

@wimdeblauwe

Description

@wimdeblauwe

Using Spring Boot 2.4.0-RC1, the @MockBean instance is not reset between tests like if I don't use nesting. You can view my example at https://github.com/wimdeblauwe/blog-example-code/tree/feature/nestedtests/nestedtests/src/test/java/com/wimdeblauwe/examples/nestedtests/music/web

There are 2 tests there: MusicRestControllerTest and MusicRestControllerNestedTest which only differ in the fact that nesting is used or not. The normal one succeeds, the nested one fails because the mock bean is not reset.

This should normally work according to #12470

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions