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:
org.springframework.test.context.TestContextBootstrapper
public class SpringBootTestContextBootstrapper extends org.springframework.test.context.support.DefaultTestContextBootstrapper
TestContextBootstrapper
for Spring Boot. Provides support for@SpringBootTest
and may also be used directly or subclassed. Provides the following features over and aboveDefaultTestContextBootstrapper
:- 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
- See Also:
SpringBootTest
,TestConfiguration
Constructor Summary
Constructors Constructor Description SpringBootTestContextBootstrapper()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.springframework.test.context.TestContext
buildTestContext()
protected org.springframework.test.context.MergedContextConfiguration
createModifiedConfig(org.springframework.test.context.MergedContextConfiguration mergedConfig, Class<?>[] classes)
Create a newMergedContextConfiguration
with different classes.protected org.springframework.test.context.MergedContextConfiguration
createModifiedConfig(org.springframework.test.context.MergedContextConfiguration mergedConfig, Class<?>[] classes, String[] propertySourceProperties)
Create a newMergedContextConfiguration
with different classes and properties.protected SpringBootTest
getAnnotation(Class<?> testClass)
protected Class<?>[]
getClasses(Class<?> testClass)
protected Class<? extends org.springframework.test.context.ContextLoader>
getDefaultContextLoaderClass(Class<?> testClass)
protected Set<Class<? extends org.springframework.test.context.TestExecutionListener>>
getDefaultTestExecutionListenerClasses()
protected String
getDifferentiatorPropertySourceProperty()
Return a "differentiator" property to ensure that there is something to differentiate regular tests and bootstrapped tests.protected Class<?>[]
getOrFindConfigurationClasses(org.springframework.test.context.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 org.springframework.test.context.MergedContextConfiguration
processMergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration mergedConfig)
protected void
processPropertySourceProperties(org.springframework.test.context.MergedContextConfiguration mergedConfig, List<String> propertySourceProperties)
Post process the property source properties, adding or removing elements as required.protected org.springframework.test.context.ContextLoader
resolveContextLoader(Class<?> testClass, List<org.springframework.test.context.ContextConfigurationAttributes> configAttributesList)
protected void
verifyConfiguration(Class<?> testClass)
Methods inherited from class org.springframework.test.context.support.AbstractTestContextBootstrapper
buildMergedContextConfiguration, getBootstrapContext, getCacheAwareContextLoaderDelegate, getContextCustomizerFactories, getDefaultTestExecutionListenerClassNames, getTestExecutionListeners, resolveExplicitContextLoaderClass, setBootstrapContext
Constructor Detail
SpringBootTestContextBootstrapper
public SpringBootTestContextBootstrapper()
Method Detail
buildTestContext
public org.springframework.test.context.TestContext buildTestContext()
- Specified by:
buildTestContext
in interfaceorg.springframework.test.context.TestContextBootstrapper
- Overrides:
buildTestContext
in classorg.springframework.test.context.support.AbstractTestContextBootstrapper
getDefaultTestExecutionListenerClasses
protected Set<Class<? extends org.springframework.test.context.TestExecutionListener>> getDefaultTestExecutionListenerClasses()
- Overrides:
getDefaultTestExecutionListenerClasses
in classorg.springframework.test.context.support.AbstractTestContextBootstrapper
resolveContextLoader
protected org.springframework.test.context.ContextLoader resolveContextLoader(Class<?> testClass, List<org.springframework.test.context.ContextConfigurationAttributes> configAttributesList)
- Overrides:
resolveContextLoader
in classorg.springframework.test.context.support.AbstractTestContextBootstrapper
getDefaultContextLoaderClass
protected Class<? extends org.springframework.test.context.ContextLoader> getDefaultContextLoaderClass(Class<?> testClass)
- Overrides:
getDefaultContextLoaderClass
in classorg.springframework.test.context.support.DefaultTestContextBootstrapper
processMergedContextConfiguration
protected org.springframework.test.context.MergedContextConfiguration processMergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration mergedConfig)
- Overrides:
processMergedContextConfiguration
in classorg.springframework.test.context.support.AbstractTestContextBootstrapper
getOrFindConfigurationClasses
protected Class<?>[] getOrFindConfigurationClasses(org.springframework.test.context.MergedContextConfiguration mergedConfig)
getDifferentiatorPropertySourceProperty
protected String 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(org.springframework.test.context.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
protected SpringBootTest.WebEnvironment getWebEnvironment(Class<?> testClass)
Return theSpringBootTest.WebEnvironment
type for this test or null if undefined.- Parameters:
testClass
- the source test class- Returns:
- the
SpringBootTest.WebEnvironment
ornull
getClasses
protected Class<?>[] getClasses(Class<?> testClass)
getProperties
protected String[] getProperties(Class<?> testClass)
getAnnotation
protected SpringBootTest getAnnotation(Class<?> testClass)
verifyConfiguration
protected void verifyConfiguration(Class<?> testClass)
createModifiedConfig
protected final org.springframework.test.context.MergedContextConfiguration createModifiedConfig(org.springframework.test.context.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 org.springframework.test.context.MergedContextConfiguration createModifiedConfig(org.springframework.test.context.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