@MockBean fields are not reset for JUnit 5 @Nested tests using @WebMvcTest #23984
Comments
I also now added a |
We stumbled over the same problem that the mocks are not cleared for nested classes. We tested spring-boot version 2.4.0 and discovered that mocks that are defined via @MockBeans on a field on the outer class are now not available for the test context that is used for inner class test methods. Is this intentional? We found a work-a-round by duplicating the |
@okrammer Duplicating the fields should not be necessary. We have an integration test where the |
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/webThere are 2 tests there:
MusicRestControllerTest
andMusicRestControllerNestedTest
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
The text was updated successfully, but these errors were encountered: