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
Ignore duplicate configuration metadata for cache key in the TestContext framework #25800
Comments
They are different, because If you don't want this to happen, you have two options.
Out of curiosity, why do you redeclare the exact same configuration on |
In any case, I'll investigate whether it's feasible to ignore such duplicate configuration metadata within a test class hierarchy for Spring Framework 5.3. |
Hi Sam, Thank you for the quick response. As to answer your question, we had no good reason (just dumb copying and pasting) to use the same However, we also didn't expect it to behave this way either. Thank you again for looking into this issue! |
I've added a "Deliverables" section to this issue's description to define and limit the scope of this issue. |
This commit ignores duplicate configuration metadata when generating the ApplicationContext cache key (i.e., MergedContextConfiguration) in the Spring TestContext Framework. This performed for the following annotations. - @ContextConfiguration - @activeprofiles - @TestPropertySource In addition, this commit reinstates validation of the rules for repeated @TestPropertySource annotations that was removed when support for @NestedTestConfiguration was introduced. Closes spring-projectsgh-25800
Current work on this issue can be viewed in the following feature branch. |
This affects 4.3
When I have a base class like:
and a child class:
I noticed Spring creates separate
ApplicationContext
for both test classes.This is not the expected behavior since according to the docs:
So by the definition outlined in the docs, these two test classes should being using the same
ApplicationContext
.When I enabled cache debugging I noticed this being logged:
when trying to retrieve the
ApplicationContext
for the base class.when trying to retrieve the
ApplicationContext
for the child class.I expect the cache key to be the same here, why is it different?
Deliverables
Ignore duplicate test configuration annotation (for the following list of annotations) when a given test class declares the exact same annotation (or equivalent merged annotation) as the next level above the current test class in the inheritance class hierarchy or enclosing class hierarchy.
Effectively, we want to remove exact duplication resulting from copy-n-paste errors before building the
MergedContextConfiguration
for a given test class.@ContextConfiguration
@ActiveProfiles
LinkedHashSet
inActiveProfilesUtils.resolveActiveProfiles()
@TestPropertySource
The text was updated successfully, but these errors were encountered: