Skip to content

Fix @BootstrapWith inheritance override issues #26645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

antoinemeyer
Copy link

@antoinemeyer antoinemeyer commented Mar 6, 2021

A @BootstrapWith annotation should be considered an override for @BootstrapWith meta-annotations not only when the @BootstrapWith annotation is directly present on the test class but also if it is present on the an ancestor of the test class.


It is common to use a base test class such as:

@SpringBootTest
public abstract class BaseTest {
}

Annotating this BaseTest with @BootstrapWith(XXX) should not make tests extending this class fail with java.lang.IllegalStateException: Configuration error: found multiple declarations of @BootstrapWith but instead properly use the @BootstrapWith as an override of the bootstrap provided as a meta-annotation by @SpringBootTest.

@pivotal-issuemaster
Copy link

@antoinemeyer Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@antoinemeyer Thank you for signing the Contributor License Agreement!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 6, 2021
@antoinemeyer antoinemeyer marked this pull request as ready for review March 6, 2021 15:13
@sbrannen
Copy link
Member

sbrannen commented Sep 6, 2023

Hi @antoinemeyer,

Thanks for submitting the PR.

I agree that we should improve the behavior here.

Your PR addresses the exact use case you have described; however, it allows a directly present @BootstrapWith annotation on a super-type to silently override local @BootstrapWith meta-annotations, which is not what one would expect.

For example, given the following ...

@BootstrapWith(BarBootstrapper.class)
@Retention(RetentionPolicy.RUNTIME)
@interface BootWithBar {}

@BootstrapWith(FooBootstrapper.class)
static class DirectBootstrapClass {}


@BootWithBar
static class InheritedDirectBootstrapAndLocalMetaBootstrapClass extends DirectBootstrapClass {}

... your proposal results in FooBootstrapper being used instead of BarBootstrapper or an exception.

In summary, I think we should improve the situation for your specific use case, but we'll need to investigate how best to avoid the pitfall I outlined above.

In light of that, I'm scheduling this for 6.1.x.

@sbrannen sbrannen added status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 6, 2023
@sbrannen sbrannen added this to the 6.1.x milestone Sep 6, 2023
@sbrannen sbrannen marked this pull request as draft September 6, 2023 08:27
Copy link
Member

@sbrannen sbrannen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have time to update this PR regarding the aforementioned pitfall, please let me know.

Otherwise, I will take a closer look in the 6.1.x time frame.

@sbrannen sbrannen changed the title Fix test context bootstrapper inheritance override Fix @BootstrapWith inheritance override issues Sep 6, 2023
@sbrannen sbrannen modified the milestones: 6.1.x, 6.1.0-RC2 Sep 14, 2023
@sbrannen sbrannen removed the status: pending-design-work Needs design work before any code can be developed label Sep 27, 2023
@sbrannen sbrannen modified the milestones: 6.1.0-RC2, 6.1.x Oct 13, 2023
@sbrannen sbrannen removed their assignment Oct 24, 2023
@sbrannen sbrannen removed this from the 6.1.x milestone Oct 24, 2023
@sbrannen sbrannen added the status: superseded An issue that has been superseded by another label Oct 24, 2023
@sbrannen
Copy link
Member

@sbrannen sbrannen closed this Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants