| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.test.context.TestContextManager
public class 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:
 
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 @Before)after test method execution:
 after any after methods of a particular testing framework (e.g.,
 JUnit 4's @After)
TestContext, 
TestExecutionListeners, 
ContextConfiguration, 
TransactionConfiguration| Constructor Summary | |
|---|---|
| TestContextManager(Class<?> testClass)Constructs a new TestContextManagerfor the specifiedtest classand automaticallyregisterstheTestExecutionListenersconfigured for
 the test class via the@TestExecutionListenersannotation. | |
| Method Summary | |
|---|---|
|  void | afterTestMethod(Object testInstance,
                Method testMethod,
                Throwable 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. | 
|  void | beforeTestMethod(Object testInstance,
                 Method testMethod)Hook for pre-processing a test before execution of the supplied test method, for example for setting up test
 fixtures, starting a transaction, etc. | 
| protected  Set<Class<? extends TestExecutionListener>> | getDefaultTestExecutionListenerClasses()Determine the default TestExecutionListenerclasses. | 
| protected  TestContext | getTestContext()Returns the TestContextmanaged by thisTestContextManager. | 
|  List<TestExecutionListener> | getTestExecutionListeners()Gets an unmodifiablecopy of
 theTestExecutionListenersregistered for
 thisTestContextManager. | 
|  void | prepareTestInstance(Object testInstance)Hook for preparing a test instance prior to execution of any individual test methods, for example for injecting dependencies, etc. | 
|  void | registerTestExecutionListeners(TestExecutionListener... testExecutionListeners)Register the supplied TestExecutionListenersby appending them to
 the set of listeners used by thisTestContextManager. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public TestContextManager(Class<?> testClass)
TestContextManager for the specified
 test class and automatically
 registers
 the TestExecutionListeners configured for
 the test class via the
 @TestExecutionListeners annotation.
testClass - the Class object corresponding to the test class to be managedregisterTestExecutionListeners(TestExecutionListener...), 
retrieveTestExecutionListeners(Class)| Method Detail | 
|---|
protected final TestContext getTestContext()
TestContext managed by this TestContextManager.
public void registerTestExecutionListeners(TestExecutionListener... testExecutionListeners)
TestExecutionListeners by appending them to
 the set of listeners used by this TestContextManager.
public final List<TestExecutionListener> getTestExecutionListeners()
unmodifiable copy of
 the TestExecutionListeners registered for
 this TestContextManager.
protected Set<Class<? extends TestExecutionListener>> getDefaultTestExecutionListenerClasses()
TestExecutionListener classes.
public void prepareTestInstance(Object testInstance)
                         throws Exception
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 exceptiongetTestExecutionListeners()
public void beforeTestMethod(Object testInstance,
                             Method testMethod)
                      throws Exception
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 @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 exceptiongetTestExecutionListeners()
public void afterTestMethod(Object testInstance,
                            Method testMethod,
                            Throwable exception)
                     throws Exception
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 @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 instanceexception - 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 exceptiongetTestExecutionListeners()| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||