Skip to content

Ignore duplicate configuration metadata for cache key in the TestContext framework #25800

@dfit99

Description

@dfit99

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions