Class SpringBootTestContextBootstrapper
java.lang.Object
org.springframework.test.context.support.AbstractTestContextBootstrapper
org.springframework.test.context.support.DefaultTestContextBootstrapper
org.springframework.boot.test.context.SpringBootTestContextBootstrapper
- All Implemented Interfaces:
TestContextBootstrapper
TestContextBootstrapper
for Spring Boot. Provides support for
@SpringBootTest
and may also be used directly or subclassed.
Provides the following features over and above DefaultTestContextBootstrapper
:
- Uses
SpringBootContextLoader
as thedefault context loader
. - Automatically searches for a
@SpringBootConfiguration
when required. - Allows custom
Environment
getProperties(Class)
to be defined. - Provides support for different
webEnvironment
modes.
- Since:
- 1.4.0
- Author:
- Phillip Webb, Andy Wilkinson, Brian Clozel, Madhura Bhave, Lorenzo Dee
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final MergedContextConfiguration
createModifiedConfig
(MergedContextConfiguration mergedConfig, Class<?>[] classes) Create a newMergedContextConfiguration
with different classes.protected final MergedContextConfiguration
createModifiedConfig
(MergedContextConfiguration mergedConfig, Class<?>[] classes, String[] propertySourceProperties) Create a newMergedContextConfiguration
with different classes and properties.protected String
determineResourceBasePath
(MergedContextConfiguration configuration) Determines the resource base path for web applications using the value of@WebAppConfiguration
, if any, on the test class of the givenconfiguration
.protected SpringBootTest
getAnnotation
(Class<?> testClass) protected Class<?>[]
getClasses
(Class<?> testClass) protected Class<? extends ContextLoader>
getDefaultContextLoaderClass
(Class<?> testClass) protected List<TestExecutionListener>
protected String
Return a "differentiator" property to ensure that there is something to differentiate regular tests and bootstrapped tests.protected Class<?>[]
getOrFindConfigurationClasses
(MergedContextConfiguration mergedConfig) protected String[]
getProperties
(Class<?> testClass) protected SpringBootTest.WebEnvironment
getWebEnvironment
(Class<?> testClass) Return theSpringBootTest.WebEnvironment
type for this test or null if undefined.protected MergedContextConfiguration
processMergedContextConfiguration
(MergedContextConfiguration mergedConfig) protected void
processPropertySourceProperties
(MergedContextConfiguration mergedConfig, List<String> propertySourceProperties) Post process the property source properties, adding or removing elements as required.protected ContextLoader
resolveContextLoader
(Class<?> testClass, List<ContextConfigurationAttributes> configAttributesList) protected void
verifyConfiguration
(Class<?> testClass) Methods inherited from class org.springframework.test.context.support.AbstractTestContextBootstrapper
buildMergedContextConfiguration, getBootstrapContext, getCacheAwareContextLoaderDelegate, getContextCustomizerFactories, getTestExecutionListeners, resolveExplicitContextLoaderClass, setBootstrapContext
-
Constructor Details
-
SpringBootTestContextBootstrapper
public SpringBootTestContextBootstrapper()
-
-
Method Details
-
buildTestContext
- Specified by:
buildTestContext
in interfaceTestContextBootstrapper
- Overrides:
buildTestContext
in classAbstractTestContextBootstrapper
-
getDefaultTestExecutionListeners
- Overrides:
getDefaultTestExecutionListeners
in classAbstractTestContextBootstrapper
-
resolveContextLoader
protected ContextLoader resolveContextLoader(Class<?> testClass, List<ContextConfigurationAttributes> configAttributesList) - Overrides:
resolveContextLoader
in classAbstractTestContextBootstrapper
-
getDefaultContextLoaderClass
- Overrides:
getDefaultContextLoaderClass
in classDefaultTestContextBootstrapper
-
processMergedContextConfiguration
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) - Overrides:
processMergedContextConfiguration
in classAbstractTestContextBootstrapper
-
determineResourceBasePath
Determines the resource base path for web applications using the value of@WebAppConfiguration
, if any, on the test class of the givenconfiguration
. Defaults tosrc/main/webapp
in its absence.- Parameters:
configuration
- the configuration to examine- Returns:
- the resource base path
- Since:
- 2.1.6
-
getOrFindConfigurationClasses
-
getDifferentiatorPropertySourceProperty
Return a "differentiator" property to ensure that there is something to differentiate regular tests and bootstrapped tests. Without this property a cached context could be returned that wasn't created by this bootstrapper. By default uses the bootstrapper class as a property.- Returns:
- the differentiator or
null
-
processPropertySourceProperties
protected void processPropertySourceProperties(MergedContextConfiguration mergedConfig, List<String> propertySourceProperties) Post process the property source properties, adding or removing elements as required.- Parameters:
mergedConfig
- the merged context configurationpropertySourceProperties
- the property source properties to process
-
getWebEnvironment
Return theSpringBootTest.WebEnvironment
type for this test or null if undefined.- Parameters:
testClass
- the source test class- Returns:
- the
SpringBootTest.WebEnvironment
ornull
-
getClasses
-
getProperties
-
getAnnotation
-
verifyConfiguration
-
createModifiedConfig
protected final MergedContextConfiguration createModifiedConfig(MergedContextConfiguration mergedConfig, Class<?>[] classes) Create a newMergedContextConfiguration
with different classes.- Parameters:
mergedConfig
- the source configclasses
- the replacement classes- Returns:
- a new
MergedContextConfiguration
-
createModifiedConfig
protected final MergedContextConfiguration createModifiedConfig(MergedContextConfiguration mergedConfig, Class<?>[] classes, String[] propertySourceProperties) Create a newMergedContextConfiguration
with different classes and properties.- Parameters:
mergedConfig
- the source configclasses
- the replacement classespropertySourceProperties
- the replacement properties- Returns:
- a new
MergedContextConfiguration
-