批注接口 SpringBootTest
@Target(TYPE)
@Retention(RUNTIME)
@Documented
@Inherited
@BootstrapWith(SpringBootTestContextBootstrapper.class)
@ExtendWith(org.springframework.test.context.junit.jupiter.SpringExtension.class)
public @interface SpringBootTest
Annotation that can be specified on a test class that runs Spring Boot based tests.
Provides the following features over and above the regular Spring TestContext
Framework:
- Uses
SpringBootContextLoaderas the defaultContextLoaderwhen no specific@ContextConfiguration(loader=...)is defined. - Automatically searches for a
@SpringBootConfigurationwhen nested@Configurationis not used, and no explicitclassesare specified. - Allows custom
Environmentproperties to be defined using theproperties attribute. - Allows application arguments to be defined using the
args attribute. - Provides support for different
webEnvironmentmodes, including the ability to start a fully running web server listening on adefinedorrandomport. - Registers a
TestRestTemplateand/orWebTestClientbean for use in web tests that are using a fully running web server.
- 从以下版本开始:
- 1.4.0
- 作者:
- Phillip Webb, Andy Wilkinson
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明static enumEnumeration of how the main method of the@SpringBootConfiguration-annotated class is used when creating and running theSpringApplicationunder test.static enumAn enumeration web environment modes. -
可选元素概要
可选元素修饰符和类型可选元素说明String[]Application arguments that should be passed to the application under test.Class<?>[]The component classes to use for loading anApplicationContext.String[]Properties in form key=value that should be added to the SpringEnvironmentbefore the test runs.The type of main method usage to employ when creating theSpringApplicationunder test.String[]Alias forproperties().The type of web environment to create when applicable.
-
元素详细资料
-
value
Alias forproperties().- 返回:
- the properties to apply
- 默认值:
{}
-
properties
Properties in form key=value that should be added to the SpringEnvironmentbefore the test runs.- 返回:
- the properties to add
- 默认值:
{}
-
args
String[] argsApplication arguments that should be passed to the application under test.- 返回:
- the application arguments to pass to the application under test.
- 从以下版本开始:
- 2.2.0
- 另请参阅:
- 默认值:
{}
-
classes
Class<?>[] classesThe component classes to use for loading anApplicationContext. Can also be specified using@ContextConfiguration(classes=...). If no explicit classes are defined the test will look for nested@Configurationclasses, before falling back to a@SpringBootConfigurationsearch.- 返回:
- the component classes used to load the application context
- 另请参阅:
- 默认值:
{}
-
webEnvironment
SpringBootTest.WebEnvironment webEnvironmentThe type of web environment to create when applicable. Defaults toSpringBootTest.WebEnvironment.MOCK.- 返回:
- the type of web environment
- 默认值:
MOCK
-
useMainMethod
SpringBootTest.UseMainMethod useMainMethodThe type of main method usage to employ when creating theSpringApplicationunder test.- 返回:
- the type of main method usage
- 从以下版本开始:
- 3.0.0
- 默认值:
NEVER
-