Uses of Interface
org.springframework.test.context.TestContext
Package
Description
This package contains the Spring TestContext Framework which
provides annotation-driven unit and integration testing support that is
agnostic of the actual testing framework in use.
Test event support classes for the Spring TestContext Framework.
JDBC support classes for the Spring TestContext Framework,
including support for declarative SQL script execution via
@Sql
.Support classes for the Spring TestContext Framework.
Transactional support classes for the Spring TestContext Framework.
Web support classes for the Spring TestContext Framework.
-
Uses of TestContext in org.springframework.test.context
Modifier and TypeMethodDescriptionTestContextBootstrapper.buildTestContext()
Build theTestContext
for theBootstrapContext
associated with this bootstrapper.final TestContext
TestContextManager.getTestContext()
Get theTestContext
managed by thisTestContextManager
.Modifier and TypeMethodDescriptiondefault void
TestExecutionListener.afterTestClass
(TestContext testContext) Post-processes a test class after execution of all tests within the class.default void
TestExecutionListener.afterTestExecution
(TestContext testContext) Post-processes a test immediately after execution of the test method in the supplied test context — for example, for timing or logging purposes.default void
TestExecutionListener.afterTestMethod
(TestContext testContext) Post-processes a test after execution of after lifecycle callbacks of the underlying test framework — for example, by tearing down test fixtures.default void
TestExecutionListener.beforeTestClass
(TestContext testContext) Pre-processes a test class before execution of all tests within the class.default void
TestExecutionListener.beforeTestExecution
(TestContext testContext) Pre-processes a test immediately before execution of the test method in the supplied test context — for example, for timing or logging purposes.default void
TestExecutionListener.beforeTestMethod
(TestContext testContext) Pre-processes a test before execution of before lifecycle callbacks of the underlying test framework — for example, by setting up test fixtures.default void
TestExecutionListener.prepareTestInstance
(TestContext testContext) Prepares the test instance of the supplied test context — for example, to inject dependencies.Modifier and TypeMethodDescriptiondefault void
TestContext.publishEvent
(Function<TestContext, ? extends ApplicationEvent> eventFactory) Publish theApplicationEvent
created by the giveneventFactory
to the application context for this test context. -
Uses of TestContext in org.springframework.test.context.event
Modifier and TypeMethodDescriptionfinal TestContext
TestContextEvent.getSource()
Get theTestContext
associated with this event.final TestContext
TestContextEvent.getTestContext()
Alias forTestContextEvent.getSource()
.Modifier and TypeMethodDescriptionvoid
EventPublishingTestExecutionListener.afterTestClass
(TestContext testContext) void
EventPublishingTestExecutionListener.afterTestExecution
(TestContext testContext) void
ApplicationEventsTestExecutionListener.afterTestMethod
(TestContext testContext) void
EventPublishingTestExecutionListener.afterTestMethod
(TestContext testContext) void
EventPublishingTestExecutionListener.beforeTestClass
(TestContext testContext) void
EventPublishingTestExecutionListener.beforeTestExecution
(TestContext testContext) void
ApplicationEventsTestExecutionListener.beforeTestMethod
(TestContext testContext) void
EventPublishingTestExecutionListener.beforeTestMethod
(TestContext testContext) void
ApplicationEventsTestExecutionListener.prepareTestInstance
(TestContext testContext) void
EventPublishingTestExecutionListener.prepareTestInstance
(TestContext testContext) ModifierConstructorDescriptionAfterTestClassEvent
(TestContext source) AfterTestExecutionEvent
(TestContext source) AfterTestMethodEvent
(TestContext source) BeforeTestClassEvent
(TestContext source) BeforeTestExecutionEvent
(TestContext source) BeforeTestMethodEvent
(TestContext source) PrepareTestInstanceEvent
(TestContext source) TestContextEvent
(TestContext source) Create a newTestContextEvent
. -
Uses of TestContext in org.springframework.test.context.jdbc
Modifier and TypeMethodDescriptionvoid
SqlScriptsTestExecutionListener.afterTestClass
(TestContext testContext) Execute SQL scripts configured via@Sql
for the suppliedTestContext
once per test class after all test methods have been run.void
SqlScriptsTestExecutionListener.afterTestMethod
(TestContext testContext) Execute SQL scripts configured via@Sql
for the suppliedTestContext
after the current test method.void
SqlScriptsTestExecutionListener.beforeTestClass
(TestContext testContext) Execute SQL scripts configured via@Sql
for the suppliedTestContext
once per test class before any test method is run.void
SqlScriptsTestExecutionListener.beforeTestMethod
(TestContext testContext) Execute SQL scripts configured via@Sql
for the suppliedTestContext
before the current test method. -
Uses of TestContext in org.springframework.test.context.support
Modifier and TypeMethodDescriptionAbstractTestContextBootstrapper.buildTestContext()
Build a newDefaultTestContext
using the test class in theBootstrapContext
associated with this bootstrapper and by delegating toAbstractTestContextBootstrapper.buildMergedContextConfiguration()
andAbstractTestContextBootstrapper.getCacheAwareContextLoaderDelegate()
.Modifier and TypeMethodDescriptionvoid
AbstractTestExecutionListener.afterTestClass
(TestContext testContext) The default implementation is empty.void
DirtiesContextTestExecutionListener.afterTestClass
(TestContext testContext) If the test class of the supplied test context is annotated with@DirtiesContext
and the class mode is set toAFTER_CLASS
, the application context of the test context will be marked as dirty, and theREINJECT_DEPENDENCIES_ATTRIBUTE
in the test context will be set totrue
.void
AbstractTestExecutionListener.afterTestExecution
(TestContext testContext) The default implementation is empty.void
AbstractTestExecutionListener.afterTestMethod
(TestContext testContext) The default implementation is empty.void
DirtiesContextTestExecutionListener.afterTestMethod
(TestContext testContext) If the current test method of the supplied test context is annotated with@DirtiesContext
and the method mode is set toAFTER_METHOD
, or if the test class is annotated with@DirtiesContext
and the class mode is set toAFTER_EACH_TEST_METHOD
, the application context of the test context will be marked as dirty and theREINJECT_DEPENDENCIES_ATTRIBUTE
in the test context will be set totrue
.protected void
AbstractDirtiesContextTestExecutionListener.beforeOrAfterTestClass
(TestContext testContext, DirtiesContext.ClassMode requiredClassMode) Perform the actual work forAbstractTestExecutionListener.beforeTestClass(org.springframework.test.context.TestContext)
andAbstractTestExecutionListener.afterTestClass(org.springframework.test.context.TestContext)
by dirtying the context if appropriate (i.e., according to the required mode).protected void
AbstractDirtiesContextTestExecutionListener.beforeOrAfterTestMethod
(TestContext testContext, DirtiesContext.MethodMode requiredMethodMode, DirtiesContext.ClassMode requiredClassMode) Perform the actual work forAbstractTestExecutionListener.beforeTestMethod(org.springframework.test.context.TestContext)
andAbstractTestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)
by dirtying the context if appropriate (i.e., according to the required modes).void
AbstractTestExecutionListener.beforeTestClass
(TestContext testContext) The default implementation is empty.void
DirtiesContextBeforeModesTestExecutionListener.beforeTestClass
(TestContext testContext) If the test class of the supplied test context is annotated with@DirtiesContext
and the class mode is set toBEFORE_CLASS
, the application context of the test context will be marked as dirty, and theREINJECT_DEPENDENCIES_ATTRIBUTE
in the test context will be set totrue
.void
AbstractTestExecutionListener.beforeTestExecution
(TestContext testContext) The default implementation is empty.void
AbstractTestExecutionListener.beforeTestMethod
(TestContext testContext) The default implementation is empty.void
DependencyInjectionTestExecutionListener.beforeTestMethod
(TestContext testContext) If theDependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE
in the suppliedtest context
has a value ofBoolean.TRUE
, this method will have the same effect asprepareTestInstance()
; otherwise, this method will have no effect.void
DirtiesContextBeforeModesTestExecutionListener.beforeTestMethod
(TestContext testContext) If the current test method of the supplied test context is annotated with@DirtiesContext
and the method mode is set toBEFORE_METHOD
, or if the test class is annotated with@DirtiesContext
and the class mode is set toBEFORE_EACH_TEST_METHOD
, the application context of the test context will be marked as dirty and theREINJECT_DEPENDENCIES_ATTRIBUTE
in the test context will be set totrue
.protected void
AbstractDirtiesContextTestExecutionListener.dirtyContext
(TestContext testContext, DirtiesContext.HierarchyMode hierarchyMode) Mark the application context of the supplied test context as dirty and setREINJECT_DEPENDENCIES_ATTRIBUTE
in the test context totrue
.protected void
DependencyInjectionTestExecutionListener.injectDependencies
(TestContext testContext) Performs dependency injection and bean initialization for the suppliedTestContext
as described inprepareTestInstance()
.void
AbstractTestExecutionListener.prepareTestInstance
(TestContext testContext) The default implementation is empty.void
DependencyInjectionTestExecutionListener.prepareTestInstance
(TestContext testContext) Performs dependency injection on thetest instance
of the suppliedtest context
byautowiring
andinitializing
the test instance via its ownapplication context
(without checking dependencies). -
Uses of TestContext in org.springframework.test.context.transaction
Modifier and TypeMethodDescriptionvoid
TransactionalTestExecutionListener.afterTestMethod
(TestContext testContext) If a transaction is currently active for the supplied test context, this method will end the transaction and run@AfterTransaction
methods.void
TransactionalTestExecutionListener.beforeTestMethod
(TestContext testContext) If the test method of the supplied test context is configured to run within a transaction, this method will run@BeforeTransaction
methods and start a new transaction.static TransactionAttribute
TestContextTransactionUtils.createDelegatingTransactionAttribute
(TestContext testContext, TransactionAttribute targetAttribute) Create a delegatingTransactionAttribute
for the supplied targetTransactionAttribute
andTestContext
, using the names of the test class and test method to build the name of the transaction.static TransactionAttribute
TestContextTransactionUtils.createDelegatingTransactionAttribute
(TestContext testContext, TransactionAttribute targetAttribute, boolean includeMethodName) Create a delegatingTransactionAttribute
for the supplied targetTransactionAttribute
andTestContext
, using the names of the test class and test method (if requested) to build the name of the transaction.protected PlatformTransactionManager
TransactionalTestExecutionListener.getTransactionManager
(TestContext testContext) Get the transaction manager to use for the supplied test context.protected PlatformTransactionManager
TransactionalTestExecutionListener.getTransactionManager
(TestContext testContext, String qualifier) protected final boolean
TransactionalTestExecutionListener.isDefaultRollback
(TestContext testContext) Determine whether to rollback transactions by default for the supplied test context.protected final boolean
TransactionalTestExecutionListener.isRollback
(TestContext testContext) Determine whether to rollback transactions for the supplied test context by taking into consideration the default rollback flag and a possible method-level override via the@Rollback
annotation.static DataSource
TestContextTransactionUtils.retrieveDataSource
(TestContext testContext, String name) Retrieve theDataSource
to use for the supplied test context.static PlatformTransactionManager
TestContextTransactionUtils.retrieveTransactionManager
(TestContext testContext, String name) Retrieve the transaction manager to use for the supplied test context.protected void
TransactionalTestExecutionListener.runAfterTransactionMethods
(TestContext testContext) Run all@AfterTransaction
methods for the specified test context.protected void
TransactionalTestExecutionListener.runBeforeTransactionMethods
(TestContext testContext) Run all@BeforeTransaction
methods for the specified test context. -
Uses of TestContext in org.springframework.test.context.web
Modifier and TypeMethodDescriptionvoid
ServletTestExecutionListener.afterTestMethod
(TestContext testContext) If theServletTestExecutionListener.RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE
in the suppliedTestContext
has a value ofBoolean.TRUE
, this method will (1) clean up thread-local state after each test method by resetting Spring Web'sRequestContextHolder
and (2) ensure that new mocks are injected into the test instance for subsequent tests by setting theDependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE
in the test context totrue
.void
ServletTestExecutionListener.beforeTestMethod
(TestContext testContext) Sets up thread-local state before each test method via Spring Web'sRequestContextHolder
, but only if the test class is annotated with@WebAppConfiguration
.void
ServletTestExecutionListener.prepareTestInstance
(TestContext testContext) Sets up thread-local state during the test instance preparation callback phase via Spring Web'sRequestContextHolder
, but only if the test class is annotated with@WebAppConfiguration
.