Spring Framework

org.springframework.test.context.testng
Class AbstractTestNGSpringContextTests

java.lang.Object
  extended by org.springframework.test.context.testng.AbstractTestNGSpringContextTests
All Implemented Interfaces:
Aware, ApplicationContextAware, org.testng.IHookable, org.testng.ITestNGListener
Direct Known Subclasses:
AbstractTransactionalTestNGSpringContextTests

@TestExecutionListeners(value={DependencyInjectionTestExecutionListener.class,DirtiesContextTestExecutionListener.class})
public abstract class AbstractTestNGSpringContextTests
extends java.lang.Object
implements org.testng.IHookable, ApplicationContextAware

Abstract base test class which integrates the Spring TestContext Framework with explicit ApplicationContext testing support in a TestNG environment.

Concrete subclasses:

Since:
2.5
Author:
Sam Brannen, Juergen Hoeller
See Also:
TestContext, TestContextManager, TestExecutionListeners, AbstractTransactionalTestNGSpringContextTests, AbstractJUnit4SpringContextTests

Field Summary
protected  ApplicationContext applicationContext
          The ApplicationContext that was injected into this test instance via setApplicationContext(ApplicationContext).
protected  org.apache.commons.logging.Log logger
          Logger available to subclasses
 
Constructor Summary
AbstractTestNGSpringContextTests()
          Construct a new AbstractTestNGSpringContextTests instance and initialize the internal TestContextManager for the current test.
 
Method Summary
 void run(org.testng.IHookCallBack callBack, org.testng.ITestResult testResult)
          Delegates to the test method in the supplied callback to execute the actual test and then tracks the exception thrown during test execution, if any.
 void setApplicationContext(ApplicationContext applicationContext)
          Set the ApplicationContext to be used by this test instance, provided via ApplicationContextAware semantics.
protected  void springTestContextAfterTestClass()
          Delegates to the configured TestContextManager to call 'after test class' callbacks.
protected  void springTestContextAfterTestMethod(java.lang.reflect.Method testMethod)
          Delegates to the configured TestContextManager to post-process the test method after the actual test has executed.
protected  void springTestContextBeforeTestClass()
          Delegates to the configured TestContextManager to call 'before test class' callbacks.
protected  void springTestContextBeforeTestMethod(java.lang.reflect.Method testMethod)
          Delegates to the configured TestContextManager to pre-process the test method before the actual test is executed.
protected  void springTestContextPrepareTestInstance()
          Delegates to the configured TestContextManager to prepare this test instance prior to execution of any individual tests, for example for injecting dependencies, etc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Logger available to subclasses


applicationContext

protected ApplicationContext applicationContext
The ApplicationContext that was injected into this test instance via setApplicationContext(ApplicationContext).

Constructor Detail

AbstractTestNGSpringContextTests

public AbstractTestNGSpringContextTests()
Construct a new AbstractTestNGSpringContextTests instance and initialize the internal TestContextManager for the current test.

Method Detail

setApplicationContext

public final void setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext to be used by this test instance, provided via ApplicationContextAware semantics.

Specified by:
setApplicationContext in interface ApplicationContextAware
Parameters:
applicationContext - the applicationContext to set
See Also:
BeanInitializationException

springTestContextBeforeTestClass

protected void springTestContextBeforeTestClass()
                                         throws java.lang.Exception
Delegates to the configured TestContextManager to call 'before test class' callbacks.

Throws:
java.lang.Exception - if a registered TestExecutionListener throws an exception

springTestContextPrepareTestInstance

protected void springTestContextPrepareTestInstance()
                                             throws java.lang.Exception
Delegates to the configured TestContextManager to prepare this test instance prior to execution of any individual tests, for example for injecting dependencies, etc.

Throws:
java.lang.Exception - if a registered TestExecutionListener throws an exception

springTestContextBeforeTestMethod

protected void springTestContextBeforeTestMethod(java.lang.reflect.Method testMethod)
                                          throws java.lang.Exception
Delegates to the configured TestContextManager to pre-process the test method before the actual test is executed.

Parameters:
testMethod - the test method which is about to be executed.
Throws:
java.lang.Exception - allows all exceptions to propagate.

run

public void run(org.testng.IHookCallBack callBack,
                org.testng.ITestResult testResult)
Delegates to the test method in the supplied callback to execute the actual test and then tracks the exception thrown during test execution, if any.

Specified by:
run in interface org.testng.IHookable
See Also:
IHookable.run(org.testng.IHookCallBack, org.testng.ITestResult)

springTestContextAfterTestMethod

protected void springTestContextAfterTestMethod(java.lang.reflect.Method testMethod)
                                         throws java.lang.Exception
Delegates to the configured TestContextManager to post-process the test method after the actual test has executed.

Parameters:
testMethod - the test method which has just been executed on the test instance
Throws:
java.lang.Exception - allows all exceptions to propagate

springTestContextAfterTestClass

protected void springTestContextAfterTestClass()
                                        throws java.lang.Exception
Delegates to the configured TestContextManager to call 'after test class' callbacks.

Throws:
java.lang.Exception - if a registered TestExecutionListener throws an exception

Spring Framework