You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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 @MockBean fields to the nested class but this makes nested classes quite unattractive for our use case.
@okrammer Duplicating the fields should not be necessary. We have an integration test where the @MockBean-annotated fields on the enclosing class are used by a nested class that verifies this behaviour. Without knowing more about your tests I can't really say why things apparently are not working for you. If you'd like us to spend some more time investigating, please open a new issue and provide a minimal sample that reproduces the behaviour that you've described.
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: