diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunner.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunner.java index d7603b8e57..f611737258 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunner.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunner.java @@ -402,12 +402,12 @@ public abstract class AbstractApplicationContextRunner registration.apply(context)); + this.runnerConfiguration.initializers.forEach((initializer) -> initializer.initialize(context)); Class[] classes = Configurations.getClasses(this.runnerConfiguration.configurations); if (classes.length > 0) { ((AnnotationConfigRegistry) context).register(classes); } - this.runnerConfiguration.beanRegistrations.forEach((registration) -> registration.apply(context)); - this.runnerConfiguration.initializers.forEach((initializer) -> initializer.initialize(context)); context.refresh(); } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java index 2fcf93ff6c..6b694a74b4 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; +import org.springframework.context.annotation.Profile; import org.springframework.core.env.Environment; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.util.ClassUtils; @@ -230,6 +231,13 @@ abstract class AbstractApplicationContextRunnerTests context.getEnvironment().setActiveProfiles("test")) + .withUserConfiguration(ProfileConfig.class) + .run((context) -> assertThat(context).hasSingleBean(ProfileConfig.class)); + } + protected abstract T get(); private static void throwCheckedException(String message) throws IOException { @@ -342,4 +350,10 @@ abstract class AbstractApplicationContextRunnerTests