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
{{ message }}
Repository navigation
Find all local @ActiveProfiles annotations on a test class #26145
Currently, multiple @ActiveProfiles declarations are discovered within a test class hierarchy (both within the inheritance hierarchy and within the enclosing class hierarchy); however, only one @ActiveProfiles declaration per class is supported, namely the first one found beginning with directly declared annotations and traversing up annotation hierarchies in search of meta-annotations.
Proposal
Initially proposed by @odrotbohm offline, it would be beneficial to support lookups for multiple @ActiveProfiles declarations on a given test class. This would allow one to create custom composed annotations that are meta-annotated with @ActiveProfiles that can be combined on a given test class in an additive fashion.
For example, given the following two composed @ProfileA and @ProfileB annotations...
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented@Inherited@ActiveProfiles("A")
public @interface ProfileA {
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented@Inherited@ActiveProfiles("B")
public @interface ProfileB {
}
... ideally one could declare both of those annotations as follows, and Spring would activate both profiles A and B.
Determine if we wish to support multiple local@ActiveProfiles declarations on a given test class.
If we decide to support this feature, determine if we wish to introduce a SpringProperties flag to disable the feature in order to support the previous semantics for backwards compatibility.
Reacted by Endre Stølsvik, Oliver Drotbohm and Eduard Gomoliako
I find this sad - I believe this is one of those issues where devs end up with "oh, that doesn't work - we'll have to hack our way around it then", typically after hours of head-scratching.
It seems like the feature would be pretty straight-forward to implement, as similar features evidently exists which do handle the @TestPropertySource, ref. #23299. It would close a very annoying, and obvious when you hit it, limitation with the framework.
It also seems like #26141, #26142 and #26145 would be fixed in an identical manner - I am certain that the combined annoyance with these deficiencies are pretty substantial if you were able to sum it up.
FWIW, I too believe this would be very useful and have found myself in the situation attempting to use something similar to the proposal from the opening comment. With the status quo, one has to be mindful of this limitation when composing custom test annotations which is unfortunate especially given how often the annotation composing as a concept is promoted in the community.
This isn't a killer feature that community is ever going to be all het up about. It's failing of Principle of Least Surprise that will slowly annoy everyone trying to create test utilities for their team. Because it's test code, people will live with hacks/hard-codings but it's a shame to leave such a gap considering the good work on meta-annotation support for several other items. That work actually makes it worse as the expectation is clearly that meta should work since it does for all those other annotations :)
Reacted by Endre Stølsvik, Oliver Drotbohm and tmoschou
changed the title [-]Find all local @ActiveProfiles annotations on a test class[/-][+]Find all local `@ActiveProfiles` annotations on a test class[/+]on Jul 6, 2023
Activity
miriSch commentedon Dec 18, 2020
Thank you sbrannen, this would definitely be useful! In fact, I could use this feature right now...
drekbour commentedon Mar 2, 2022
Related SO https://stackoverflow.com/questions/26176038/activeprofiles-in-meta-annotation-and-on-test-class-not-working
This would be very handy (as is the recent work on
@TestPropertySource#23299) in making composed annotations to reduce boilerplate in tests.sbrannen commentedon Jun 7, 2022
Since the community has not displayed significant interest in this feature during the last 1.5 years, the team has decided to close this issue.
However, if the community displays increased interest in this feature we would be willing to reconsider.
stolsvik commentedon Jun 7, 2022
I find this sad - I believe this is one of those issues where devs end up with "oh, that doesn't work - we'll have to hack our way around it then", typically after hours of head-scratching.
It seems like the feature would be pretty straight-forward to implement, as similar features evidently exists which do handle the @TestPropertySource, ref. #23299. It would close a very annoying, and obvious when you hit it, limitation with the framework.
stolsvik commentedon Jun 7, 2022
It also seems like #26141, #26142 and #26145 would be fixed in an identical manner - I am certain that the combined annoyance with these deficiencies are pretty substantial if you were able to sum it up.
vpavic commentedon Jun 7, 2022
FWIW, I too believe this would be very useful and have found myself in the situation attempting to use something similar to the proposal from the opening comment. With the status quo, one has to be mindful of this limitation when composing custom test annotations which is unfortunate especially given how often the annotation composing as a concept is promoted in the community.
drekbour commentedon Jun 7, 2022
This isn't a killer feature that community is ever going to be all het up about. It's failing of Principle of Least Surprise that will slowly annoy everyone trying to create test utilities for their team. Because it's test code, people will live with hacks/hard-codings but it's a shame to leave such a gap considering the good work on meta-annotation support for several other items. That work actually makes it worse as the expectation is clearly that meta should work since it does for all those other annotations :)
[-]Find all local @ActiveProfiles annotations on a test class[/-][+]Find all local `@ActiveProfiles` annotations on a test class[/+]teleivo commentedon Jul 17, 2024
This would be a great to have. This behavior also surprised me 😬