-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
This affects 4.3
When I have a base class like:
@ContextConfiguration(classes = A.class)
class Base extends AbstractTestNGSpringContextTests {}
and a child class:
@ContextConfiguration(classes = A.class)
class Child extends Base {}
I noticed Spring creates separate ApplicationContext
for both test classes.
This is not the expected behavior since according to the docs:
An ApplicationContext can be uniquely identified by the combination of configuration parameters that are used to load it
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:
Storing ApplicationContext in cache under key [[MergedContextConfiguration@4f190018 testClass = Base, locations = '{}', classes = '{class A}
when trying to retrieve the ApplicationContext
for the base class.
Storing ApplicationContext in cache under key [[MergedContextConfiguration@4f190017 testClass = Child, locations = '{}', classes = '{class A, class A}
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
- duplicates are already removed via the use of a
LinkedHashSet
inActiveProfilesUtils.resolveActiveProfiles()
- See also @ActiveProfiles with same profiles but different order results in duplicate ApplicationContext #25973
- duplicates are already removed via the use of a
-
@TestPropertySource