批注接口 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
SpringBootContextLoader
as the defaultContextLoader
when no specific@ContextConfiguration(loader=...)
is defined. - Automatically searches for a
@SpringBootConfiguration
when nested@Configuration
is not used, and no explicitclasses
are specified. - Allows custom
Environment
properties to be defined using theproperties attribute
. - Allows application arguments to be defined using the
args attribute
. - Provides support for different
webEnvironment
modes, including the ability to start a fully running web server listening on adefined
orrandom
port. - Registers a
TestRestTemplate
and/orWebTestClient
bean for use in web tests that are using a fully running web server.
- 从以下版本开始:
- 1.4.0
- 作者:
- Phillip Webb, Andy Wilkinson
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明static enum
Enumeration of how the main method of the@SpringBootConfiguration
-annotated class is used when creating and running theSpringApplication
under test.static enum
An 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 SpringEnvironment
before the test runs.The type of main method usage to employ when creating theSpringApplication
under 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 SpringEnvironment
before 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@Configuration
classes, before falling back to a@SpringBootConfiguration
search.- 返回:
- 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 theSpringApplication
under test.- 返回:
- the type of main method usage
- 从以下版本开始:
- 3.0.0
- 默认值:
NEVER
-