Class AbstractTestNGSpringContextTests
java.lang.Object
org.springframework.test.context.testng.AbstractTestNGSpringContextTests
- All Implemented Interfaces:
- Aware,- ApplicationContextAware,- org.testng.IHookable,- org.testng.ITestNGListener
- Direct Known Subclasses:
- AbstractTransactionalTestNGSpringContextTests
public abstract class AbstractTestNGSpringContextTests
extends 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 should typically declare a class-level
 @ContextConfiguration annotation to
 configure the application context resource locations or component classes. Concrete subclasses must
 also have constructors which either implicitly or explicitly delegate to
 super();.
- Since:
- 2.5
- Author:
- Sam Brannen, Juergen Hoeller
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected ApplicationContextTheApplicationContextthat was injected into this test instance viasetApplicationContext(ApplicationContext).protected final LogLogger available to subclasses.
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct a newAbstractTestNGSpringContextTestsinstance and initialize the internalTestContextManagerfor the current test class.
- 
Method SummaryModifier and TypeMethodDescriptionvoidrun(org.testng.IHookCallBack callBack, org.testng.ITestResult testResult) Delegates to the test method in the suppliedcallbackto execute the actual test and then tracks the exception thrown during test execution, if any.final voidsetApplicationContext(ApplicationContext applicationContext) Set theApplicationContextto be used by this test instance, provided viaApplicationContextAwaresemantics.protected voidDelegates to the configuredTestContextManagerto call 'after test class' callbacks.protected voidspringTestContextAfterTestMethod(Method testMethod) Delegates to the configuredTestContextManagerto post-process the test method after the actual test has executed.protected voidDelegates to the configuredTestContextManagerto call 'before test class' callbacks.protected voidspringTestContextBeforeTestMethod(Method testMethod) Delegates to the configuredTestContextManagerto pre-process the test method before the actual test is executed.protected voidDelegates to the configuredTestContextManagerto prepare this test instance prior to execution of any individual tests, for example for injecting dependencies, etc.
- 
Field Details- 
loggerLogger available to subclasses.
- 
applicationContextTheApplicationContextthat was injected into this test instance viasetApplicationContext(ApplicationContext).
 
- 
- 
Constructor Details- 
AbstractTestNGSpringContextTestspublic AbstractTestNGSpringContextTests()Construct a newAbstractTestNGSpringContextTestsinstance and initialize the internalTestContextManagerfor the current test class.
 
- 
- 
Method Details- 
setApplicationContextSet theApplicationContextto be used by this test instance, provided viaApplicationContextAwaresemantics.- Specified by:
- setApplicationContextin interface- ApplicationContextAware
- Parameters:
- applicationContext- the ApplicationContext that this test runs in
- See Also:
 
- 
springTestContextBeforeTestClassDelegates to the configuredTestContextManagerto call 'before test class' callbacks.- Throws:
- Exception- if a registered TestExecutionListener throws an exception
 
- 
springTestContextPrepareTestInstance@BeforeClass(alwaysRun=true, dependsOnMethods="springTestContextBeforeTestClass") protected void springTestContextPrepareTestInstance() throws ExceptionDelegates to the configuredTestContextManagerto prepare this test instance prior to execution of any individual tests, for example for injecting dependencies, etc.- Throws:
- Exception- if a registered TestExecutionListener throws an exception
 
- 
springTestContextBeforeTestMethod@BeforeMethod(alwaysRun=true) protected void springTestContextBeforeTestMethod(Method testMethod) throws Exception Delegates to the configuredTestContextManagerto pre-process the test method before the actual test is executed.- Parameters:
- testMethod- the test method which is about to be executed
- Throws:
- Exception- allows all exceptions to propagate
 
- 
runpublic void run(org.testng.IHookCallBack callBack, org.testng.ITestResult testResult) Delegates to the test method in the suppliedcallbackto execute the actual test and then tracks the exception thrown during test execution, if any.- Specified by:
- runin interface- org.testng.IHookable
- See Also:
- 
- IHookable.run(IHookCallBack, ITestResult)
 
 
- 
springTestContextAfterTestMethod@AfterMethod(alwaysRun=true) protected void springTestContextAfterTestMethod(Method testMethod) throws Exception Delegates to the configuredTestContextManagerto 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:
- Exception- allows all exceptions to propagate
 
- 
springTestContextAfterTestClassDelegates to the configuredTestContextManagerto call 'after test class' callbacks.- Throws:
- Exception- if a registered TestExecutionListener throws an exception
 
 
-