Skip to content
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

@DynamicPropertySource is not supported via @NestedTestConfiguration semantics #26091

Closed
fbiville opened this issue Nov 13, 2020 · 2 comments
Closed
Assignees
Labels
in: test Issues in the test module type: enhancement A general enhancement
Milestone

Comments

@fbiville
Copy link

fbiville commented Nov 13, 2020

Reproduced with Spring Framework 5.3.1 (via Spring Boot 2.4.0).

As initially described here and here, nested tests do not work with @DynamicPropertySource.

You can reproduce the issue with this sample Spring Data JPA (2.4.1) repository: https://github.com/fbiville/spring-data-jpa-nested (see README for reproduction one-liners).

As suggested by @wilkinsona here, replacing the annotation with ApplicationContextInitializer works.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 13, 2020
@sbrannen sbrannen added the in: test Issues in the test module label Nov 13, 2020
@sbrannen sbrannen self-assigned this Nov 13, 2020
@sbrannen sbrannen added this to the 5.3.2 milestone Nov 13, 2020
@sbrannen sbrannen changed the title Nested test support currently does not work with DynamicPropertySource @DynamicPropertySource is not supported via @NestedTestConfiguration semantics Nov 13, 2020
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 13, 2020
@sbrannen
Copy link
Member

Thanks so much for raising the issue!

When implementing #19930, my goal was to provide support for inheriting enclosing class configuration for all class-level annotations; however, I simply overlooked @DynamicPropertySource in the process.

@DynamicPropertySource is technically a static method-level annotation, but it in fact contributes to the context cache key in the Spring TestContext Framework.

So I apologize for missing that.

I've already reproduced the issue in an integration test using only the Spring Framework, and the fix requires some changes in DynamicPropertiesContextCustomizerFactory to honor @NestedTestConfiguration semantics. So I'll make sure to provide proper support for inheriting @DynamicPropertySource configuration in @Nested test classes in Spring Framework 5.3.2.

@sbrannen
Copy link
Member

I've added support for inheriting @DynamicPropertySource methods from enclosing classes.

This will be released with Spring Framework 5.3.2, but feel free to try it out in an upcoming snapshot.

As a workaround for 5.3.0 and 5.3.1, you can create a test base class (typically abstract) or test interface that only includes the @DynamicPropertySource method and then extend or implement that class or interface in each @Nested test class that needs it. Examples can be seen in the DynamicPropertySourceFromSuperclassTests and DynamicPropertySourceFromInterfaceTests nested test classes in DynamicPropertySourceNestedTests.

sbrannen pushed a commit that referenced this issue Aug 21, 2023
… class

Prior to this commit, a dynamic property registered via a
@DynamicPropertySource method in a @nested test class was not able to
override a property registered via a @DynamicPropertySource method in
the enclosing class.

See gh-26091
Closes gh-31083
sbrannen pushed a commit to sbrannen/spring-framework that referenced this issue Aug 21, 2023
… class

Prior to this commit, a dynamic property registered via a
@DynamicPropertySource method in a @nested test class was not able to
override a property registered via a @DynamicPropertySource method in
the enclosing class.

See spring-projectsgh-26091
Closes spring-projectsgh-31083
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 type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants