GH-253 - Let @ApplicationModuleTest be meta-annotated with @SpringBootTest.

@ApplicationModuleTest is now meta-annotated with @SpringBootTest. This allows us to remove a couple of declarations that we actually had copied from it (such as the TestContextBootstrapper, the SpringExtension etc.)

The presence of the original annotation allow test-related auto-configuration to inspect @SprignBootTest for particular configuration. For example, we now alias the WebEnvironment to make it configurable for the test execution.
This commit is contained in:
Oliver Drotbohm
2023-08-01 23:58:17 +02:00
parent d665161c37
commit 3055212e4b
3 changed files with 40 additions and 5 deletions

View File

@@ -27,13 +27,12 @@ import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters;
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.core.annotation.AliasFor;
import org.springframework.modulith.core.DependencyDepth;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.TestConstructor;
import org.springframework.test.context.TestConstructor.AutowireMode;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Bootstraps the module containing the package of the test class annotated with {@link ApplicationModuleTest}. Will
@@ -49,10 +48,10 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@BootstrapWith(SpringBootTestContextBootstrapper.class)
@SpringBootTest
@TypeExcludeFilters(ModuleTypeExcludeFilter.class)
@ImportAutoConfiguration(ModuleTestAutoConfiguration.class)
@ExtendWith({ SpringExtension.class, PublishedEventsParameterResolver.class, ScenarioParameterResolver.class })
@ExtendWith({ PublishedEventsParameterResolver.class, ScenarioParameterResolver.class })
@TestInstance(Lifecycle.PER_CLASS)
@TestConstructor(autowireMode = AutowireMode.ALL)
public @interface ApplicationModuleTest {
@@ -77,6 +76,14 @@ public @interface ApplicationModuleTest {
*/
String[] extraIncludes() default {};
/**
* The type of web environment to create when applicable. Defaults to {@link WebEnvironment#MOCK}.
*
* @return the type of web environment
*/
@AliasFor(annotation = SpringBootTest.class)
WebEnvironment webEnvironment() default WebEnvironment.MOCK;
public enum BootstrapMode {
/**