Annotation Interface 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.
- Since:
- 1.4.0
- Author:
- Phillip Webb, Andy Wilkinson
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
An enumeration web environment modes. -
Optional Element Summary
Modifier and TypeOptional ElementDescriptionString[]
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.String[]
Alias forproperties()
.The type of web environment to create when applicable.
-
Element Details
-
value
Alias forproperties()
.- Returns:
- the properties to apply
- Default:
- {}
-
properties
Properties in form key=value that should be added to the SpringEnvironment
before the test runs.- Returns:
- the properties to add
- Default:
- {}
-
args
String[] argsApplication arguments that should be passed to the application under test.- Returns:
- the application arguments to pass to the application under test.
- Since:
- 2.2.0
- See Also:
- Default:
- {}
-
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.- Returns:
- the component classes used to load the application context
- See Also:
- Default:
- {}
-
webEnvironment
SpringBootTest.WebEnvironment webEnvironmentThe type of web environment to create when applicable. Defaults toSpringBootTest.WebEnvironment.MOCK
.- Returns:
- the type of web environment
- Default:
- MOCK
-