Skip to content

Find all local @ContextConfiguration annotations on a test class #26142

Closed as not planned

Description

@stolsvik

Very similar to issue #26141, I find that ContextConfiguration should be able to append to an existing ContextConfiguration. But this seems to not be possible.

This is unfortunate as the ContextConfiguration can be used as a meta-annotation. I've tried to make some nice bespoke annotations that can be used in our shop that can be slapped on the test case - but that fails if the test also includes a @ContextConfiguration annotation - or a second bespoke annotation that also needs to add itself as a ContextConfiguration.

This "only one" seems like this also holds even if the first specifies initializers, and the other classes.

(What actually still works, though, is the feature where any inner static classes annotated with Configuration is automatically picked up without ContextConfiguration pointing to it: This still works if initializers is specified, but not if classes is specified. The latter seems strange; Would it not be nice if I could point to existing app Configuration classes using the @ContextConfiguration, and then include some test-specific Configuration classes as inner classes without having to also include those in the classes-list?)

Maybe a parameter "append=true" would suffice here?

Activity

  1. added
    status: waiting-for-triage
    on Nov 23, 2020
  2. added
    in: test
    type: enhancement
    on Nov 24, 2020
  3. changed the title [-]Test framework: ContextConfiguration "append", not single per test[/-] [+]Find all local @ContextConfiguration annotations on a test class[/+] on Nov 24, 2020
  4. sbrannen commented on Nov 24, 2020

    @sbrannen
    Member

    Thanks for raising the issue.

    I have created #26145 which is a similar request for @ActiveProfiles, and we will consider this in conjunction with that issue.

  5. stolsvik commented on Nov 24, 2020

    @stolsvik
    Author

    @sbrannen As with my comment on #26141, I am not sure I agree to the title change? Or, I might not understand what you mean by "local".

    For my part, I wish the test framework would "collate" all @ContextConfigurations in the scope of the test.

    Specifically, I would like to use the @ContextConfiguration as a meta-annotation on an annotation @MatsSimpleTestContext which sets up a standard set of beans often needed in testing, for my "Mats" library. The problem is if the test-class also specifies ContextConfiguration, then my annotation's wishes simply vanishes.

    I find such an annotation much nicer and succinct than explaining that you must either include MatsTestInfrastructureConfiguration in your list of configuration classes, or place an @import annotation on an inner static @configuration class. All other such Components and Configurations you import probably relate to your actual application - this Mats-library-specific Configuration class looks out of place in such a list; Much nicer then with a direct "enable"-style library-specific annotation.

    As mentioned, an extra property "append=true" or something could be used to point out that such collating was the desired operation.

  6. sbrannen commented on Jun 7, 2022

    @sbrannen
    Member

    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.

  7. added
    status: declined
    and removed
    status: waiting-for-triage
    on Jun 7, 2022
  8. stolsvik commented on Jun 7, 2022

    @stolsvik
    Author

    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.

  9. stolsvik commented on Jun 7, 2022

    @stolsvik
    Author

    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.

  10. changed the title [-]Find all local @ContextConfiguration annotations on a test class[/-] [+]Find all local `@ContextConfiguration` annotations on a test class[/+] on Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: teststatus: declinedtype: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions