Since 7.1.0-M1 spring-test changes the logic calculating the MergedContextConfiguration entity for the nested test class. Consider example:
@SpringBootTest(classes = {
EnclosingTest.Configuration.class
})
class EnclosingTest {
class NestedTest {
Before 7.1.0-M1 both EnclosingTest and EnclosingTest.NestedTest had equal MergedContextConfiguration which also means that the same application context is reused between them.
But now it's changed. The MergedContextConfiguration are different, the nested class now has TWO classes in the classes fields (both the same).
Most probably it is related to this change between 7.0 and 7.1 (also doc):
List<ContextConfigurationAttributes> defaultConfigAttributesList =
Collections.singletonList(new ContextConfigurationAttributes(testClass));
// for 7.1: ContextLoaderUtils.resolveDefaultContextConfigurationAttributes(testClass);
Crucial detail
After some research it was found, that this depends on the presence of @ContextConfiguration on the enclosing class. If there is a declaration like this:
@SpringBootTest(classes = {
EnclosingTest.Configuration.class
})
@ContextConfiguration
class EnclosingTest {
class NestedTest {
then the test cache behaves as expected.
Most probably it works correctly because of this condition in AbstractTestContextBootstrapper:
@Override
public final MergedContextConfiguration buildMergedContextConfiguration() {
...
// is evaluated to false (annotation found) if @ContextConfiguration is present, and the branch skipped
if (TestContextAnnotationUtils.findAnnotationDescriptorForTypes(
testClass, ContextConfiguration.class, ContextHierarchy.class) == null) {
return buildDefaultMergedContextConfiguration(testClass, cacheAwareContextLoaderDelegate);
}
So, the question is: is it a desired behavior for @SpringBootTest (which is not a meta-annotation of @ContextConfiguration), or it's a bug?
Since
7.1.0-M1spring-test changes the logic calculating theMergedContextConfigurationentity for the nested test class. Consider example:Before
7.1.0-M1bothEnclosingTestandEnclosingTest.NestedTesthad equalMergedContextConfigurationwhich also means that the same application context is reused between them.But now it's changed. The
MergedContextConfigurationare different, the nested class now has TWOclassesin the classes fields (both the same).Most probably it is related to this change between 7.0 and 7.1 (also doc):
Crucial detail
After some research it was found, that this depends on the presence of
@ContextConfigurationon the enclosing class. If there is a declaration like this:then the test cache behaves as expected.
Most probably it works correctly because of this condition in
AbstractTestContextBootstrapper:So, the question is: is it a desired behavior for
@SpringBootTest(which is not a meta-annotation of@ContextConfiguration), or it's a bug?