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
Spring Framework 5.3 has added support for discovering tested configuration on an enclosing class. This is useful when using JUnit Jupiter's @Nested as it allows test configuration to be declared once (on the enclosing class) and then reused (by all the nested classes).
@MockUser should participate in this behaviour so that it can be declared once on the enclosing class and used by all the nested classes.
Current Behavior
@MockUser on the enclosing class is ignored when running the nested tests and most be redeclared on each @Nested test class.
Context
This is part of providing consistent testing support across the portfolio. The current inconsistencies make it hard for users to know when they can declare configuration once and when it must be repeated.
wilkinsona
changed the title
Build on Framework's support the nested test configuration discovery and inherit WithMockUser from enclosing class
Build on Framework's support for nested test configuration discovery and inherit WithMockUser from enclosing class
Nov 2, 2020
rwinch
changed the title
Build on Framework's support for nested test configuration discovery and inherit WithMockUser from enclosing class
WithSecurityContextTestExecutionListener Should Support Nested Classes
Nov 3, 2020
The WithMockUser support needs to work a little differently than the nested support in test. The support within TestContextAnnotationUtils requires EnclosingConfiguration.INHERIT but Spring Security's test support does not require an ApplicationContext to be present. Instead, WithSecurityContext and the related annotations are used unless overridden by a more specific location.
The WithMockUser support needs to work a little differently than the nested support in test.
Why should it work differently than other test annotations in the Spring portfolio?
The support within TestContextAnnotationUtils requires EnclosingConfiguration.INHERIT but Spring Security's test support does not require an ApplicationContext to be present.
TestContextAnnotationUtils does not require that an ApplicationContext be present. Rather, TestContextAnnotationUtils provides support for looking up any class-level annotations that are used within tests while honoring the new @NestedTestConfiguration semantics.
Note that EnclosingConfiguration.INHERIT is the default behavior in Spring Framework 5.3, but it's configurable via the SpringProperties mechanism and @NestedTestConfiguration.
Instead, WithSecurityContext and the related annotations are used unless overridden by a more specific location.
In 87d8741, I see that you do not make use of TestContextAnnotationUtils. Can you please explain the rationale for that?
@sbrannen Thank you for your review. This turns out it was a just a series of misunderstandings on my part. I went created and resolved gh-9193 to address your concerns.
Expected Behavior
Spring Framework 5.3 has added support for discovering tested configuration on an enclosing class. This is useful when using JUnit Jupiter's
@Nested
as it allows test configuration to be declared once (on the enclosing class) and then reused (by all the nested classes).@MockUser
should participate in this behaviour so that it can be declared once on the enclosing class and used by all the nested classes.Current Behavior
@MockUser
on the enclosing class is ignored when running the nested tests and most be redeclared on each@Nested
test class.Context
This is part of providing consistent testing support across the portfolio. The current inconsistencies make it hard for users to know when they can declare configuration once and when it must be repeated.
/cc @sbrannen
The text was updated successfully, but these errors were encountered: