java.lang.Object | |
↳ | org.springframework.test.context.TestContextManager |
TestContextManager
is the main entry point into the
Spring TestContext Framework, which provides support for loading and
accessing application contexts
, dependency
injection of test instances,
transactional
execution of test methods, etc.
Specifically, a TestContextManager
is responsible for managing a
single TestContext
and signaling events to all registered
TestExecutionListeners
at well defined test
execution points:
before test class execution
: prior to any
before class methods of a particular testing framework (e.g., JUnit
4's org.junit.BeforeClass @BeforeClass)test instance preparation
:
immediately following instantiation of the test instancebefore test method execution
:
prior to any before methods of a particular testing framework (e.g.,
JUnit 4's org.junit.Before @Before)after test method
execution
: after any after methods of a particular testing
framework (e.g., JUnit 4's org.junit.After @After)after test class execution
: after any
after class methods of a particular testing framework (e.g., JUnit
4's org.junit.AfterClass @AfterClass)Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Delegates to
TestContextManager(Class, String) with a value of
null for the default ContextLoader class name. | |||||||||||
Constructs a new
TestContextManager for the specified test class
and automatically registers the
TestExecutionListeners configured for the test class
via the @TestExecutionListeners annotation. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Hook for post-processing a test class after execution of all
tests within the class.
| |||||||||||
Hook for post-processing a test after execution of the supplied
test method , for example for tearing down test fixtures,
ending a transaction, etc. | |||||||||||
Hook for pre-processing a test class before execution of any
tests within the class.
| |||||||||||
Hook for pre-processing a test before execution of the supplied
test method , for example for setting up test fixtures,
starting a transaction, etc. | |||||||||||
Get the current
TestExecutionListeners
registered for this TestContextManager . | |||||||||||
Hook for preparing a test instance prior to execution of any individual
test methods, for example for injecting dependencies, etc.
| |||||||||||
Register the supplied
TestExecutionListeners
by appending them to the set of listeners used by this TestContextManager . |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Determine the default
TestExecutionListener classes. | |||||||||||
Returns the
TestContext managed by this
TestContextManager . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Delegates to TestContextManager(Class, String)
with a value of
null
for the default ContextLoader
class name.
Constructs a new TestContextManager
for the specified test class
and automatically registers
the
TestExecutionListeners
configured for the test class
via the @TestExecutionListeners
annotation.
testClass | the test class to be managed |
---|---|
defaultContextLoaderClassName | the name of the default
ContextLoader class to use (may be null ) |
registerTestExecutionListeners(TestExecutionListener)
Hook for post-processing a test class after execution of all tests within the class. Should be called after any framework-specific after class methods (e.g., methods annotated with JUnit's org.junit.AfterClass @AfterClass).
Each registered TestExecutionListener
will be given a chance to
post-process the test class. If a listener throws an exception, the
remaining registered listeners will still be called, but the first
exception thrown will be tracked and rethrown after all listeners have
executed. Note that registered listeners will be executed in the opposite
order in which they were registered.
Exception | if a registered TestExecutionListener throws an exception |
---|
Hook for post-processing a test after execution of the supplied
test method
, for example for tearing down test fixtures,
ending a transaction, etc. Should be called after any framework-specific
after methods (e.g., methods annotated with JUnit's
org.junit.After @After).
The managed TestContext
will be updated with the supplied
testInstance
, testMethod
, and
exception
.
Each registered TestExecutionListener
will be given a chance to
post-process the test method execution. If a listener throws an
exception, the remaining registered listeners will still be called, but
the first exception thrown will be tracked and rethrown after all
listeners have executed. Note that registered listeners will be executed
in the opposite order in which they were registered.
testInstance | the current test instance (never null ) |
---|---|
testMethod | the test method which has just been executed on the test instance |
exception | the exception that was thrown during execution of the
test method or by a TestExecutionListener, or null if none
was thrown |
Exception | if a registered TestExecutionListener throws an exception |
---|
Hook for pre-processing a test class before execution of any tests within the class. Should be called prior to any framework-specific before class methods (e.g., methods annotated with JUnit's org.junit.BeforeClass @BeforeClass).
An attempt will be made to give each registered
TestExecutionListener
a chance to pre-process the test class
execution. If a listener throws an exception, however, the remaining
registered listeners will not be called.
Exception | if a registered TestExecutionListener throws an exception |
---|
Hook for pre-processing a test before execution of the supplied
test method
, for example for setting up test fixtures,
starting a transaction, etc. Should be called prior to any
framework-specific before methods (e.g., methods annotated with
JUnit's org.junit.Before @Before).
The managed TestContext
will be updated with the supplied
testInstance
and testMethod
.
An attempt will be made to give each registered
TestExecutionListener
a chance to pre-process the test method
execution. If a listener throws an exception, however, the remaining
registered listeners will not be called.
testInstance | the current test instance (never null ) |
---|---|
testMethod | the test method which is about to be executed on the test instance |
Exception | if a registered TestExecutionListener throws an exception |
---|
Get the current TestExecutionListeners
registered for this TestContextManager
.
Allows for modifications, e.g. adding a listener to the beginning of the list. However, make sure to keep the list stable while actually executing tests.
Hook for preparing a test instance prior to execution of any individual test methods, for example for injecting dependencies, etc. Should be called immediately after instantiation of the test instance.
The managed TestContext
will be updated with the supplied
testInstance
.
An attempt will be made to give each registered
TestExecutionListener
a chance to prepare the test instance. If a
listener throws an exception, however, the remaining registered listeners
will not be called.
testInstance | the test instance to prepare (never null ) |
---|
Exception | if a registered TestExecutionListener throws an exception |
---|
Register the supplied TestExecutionListeners
by appending them to the set of listeners used by this TestContextManager
.
Determine the default TestExecutionListener
classes.
Returns the TestContext
managed by this
TestContextManager
.