- 
                Notifications
    
You must be signed in to change notification settings  - Fork 38.8k
 
Description
Dave Syer opened SPR-11455 and commented
Overview
I guess it all works when the annotation is @ContextConfiguration but when it is a composed annotation (i.e., an annotation meta-annotated with @ContextConfiguration) then the test framework all goes a bit haywire. I think if this bug were fixed then custom annotations composed with @ContextConfiguration would pick up the default context locations or configuration classes automatically. As things stand they don't, and there's no workaround as far as I can tell.
Analysis
ContextConfigurationAttributes has a declaringClass attribute that looks as if it is supposed to contain the test class. ContextLoaderUtils.resolveContextConfigurationAttributes(Class) loses that information somehow, maybe by using the declaringClass instead of the rootDeclaringClass of the AnnotationDescriptor it is working with, or maybe because the ContextConfigurationAttributes needs a new property for the rootDeclaringClass (my guess is the former because who would need the meta-annotation class)?
Further Analysis
The same problem applies to the @ContextHierarchy processing code, and a similar problem exists for the invocation of ActiveProfilesResolver instances (see #16093).
Consequences
One consequence is that there is no way for a ContextLoader (or SmartContextLoader) to access the declaring test class to discover default resource locations or configuration classes when @ContextConfiguration is used as a meta-annotation.
Affects: 4.0 GA
Attachments:
- spring-test-4.0.3.BUILD-SNAPSHOT.jar (437.47 kB)
 
Issue Links:
- Provide meta-annotation support for test-related annotations [SPR-7827] #12483 Provide meta-annotation support for test-related annotations
 - Support meta-annotation attribute overrides in the TestContext framework [SPR-11038] #15666 Support meta-annotation attribute overrides in the TestContext framework
 - @Configuration class is not detected as default in composed annotation in the TestContext framework [SPR-11641] #16264 
@Configurationclass is not detected as default in composed annotation in the TestContext framework - ActiveProfilesResolver is supplied composed annotation class instead of test class [SPR-11467] #16093 ActiveProfilesResolver is supplied composed annotation class instead of test class