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 default ContextLoader when no specific @ContextConfiguration(loader=...) is defined.
- Automatically searches for a @SpringBootConfiguration when nested
@Configuration
is not used, and no explicit classes are specified. - Allows custom Environment properties to be defined using the properties 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 a defined or random port.
- Registers a TestRestTemplate and/or WebTestClient bean for use in web tests that are using a fully running web server.
Author
Phillip Webb
Andy Wilkinson
Since
1.4.0
See also
Types
Link copied to clipboard
enum UseMainMethod
Enumeration of how the main method of the @SpringBootConfiguration-annotated class is used when creating and running the SpringApplication under test.
Link copied to clipboard
enum WebEnvironment
An enumeration web environment modes.
Functions
Link copied to clipboard
Link copied to clipboard
Properties in form key=value that should be added to the Spring Environment before the test runs.
Link copied to clipboard
The type of main method usage to employ when creating the SpringApplication under test.
Link copied to clipboard
The type of web environment to create when applicable.