public abstract class

AbstractTestNGSpringContextTests

extends Object
implements ApplicationContextAware
java.lang.Object
   ↳ org.springframework.test.context.testng.AbstractTestNGSpringContextTests
Known Direct Subclasses

Class Overview

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

Concrete subclasses:

  • Typically declare a class-level @ContextConfiguration annotation to configure the application context ContextConfiguration#locations() resource locations. If your test does not need to load an application context, you may choose to omit the @ContextConfiguration declaration and to configure the appropriate TestExecutionListeners manually.
  • Must have constructors which either implicitly or explicitly delegate to super();.

Summary

Fields
protected ApplicationContext applicationContext The ApplicationContext that was injected into this test instance via setApplicationContext(ApplicationContext).
protected final Log logger Logger available to subclasses
Public Constructors
AbstractTestNGSpringContextTests()
Construct a new AbstractTestNGSpringContextTests instance and initialize the internal TestContextManager for the current test.
Public Methods
void run(IHookCallBack callBack, ITestResult testResult)
Delegates to the IHookCallBack#runTestMethod(ITestResult) test method in the supplied callback to execute the actual test and then tracks the exception thrown during test execution, if any.
final void setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext to be used by this test instance, provided via ApplicationContextAware semantics.
Protected Methods
void springTestContextAfterTestClass()
Delegates to the configured TestContextManager to call 'after test class' callbacks.
void springTestContextAfterTestMethod(Method testMethod)
Delegates to the configured TestContextManager to post-process the test method after the actual test has executed.
void springTestContextBeforeTestClass()
Delegates to the configured TestContextManager to call 'before test class' callbacks.
void springTestContextBeforeTestMethod(Method testMethod)
Delegates to the configured TestContextManager to pre-process the test method before the actual test is executed.
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.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.context.ApplicationContextAware

Fields

protected ApplicationContext applicationContext

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

protected final Log logger

Logger available to subclasses

Public Constructors

public AbstractTestNGSpringContextTests ()

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

Public Methods

public void run (IHookCallBack callBack, ITestResult testResult)

Delegates to the IHookCallBack#runTestMethod(ITestResult) test method in the supplied callback to execute the actual test and then tracks the exception thrown during test execution, if any.

See Also
  • org.testng.IHookable#run(org.testng.IHookCallBack, org.testng.ITestResult)

public final void setApplicationContext (ApplicationContext applicationContext)

Set the ApplicationContext to be used by this test instance, provided via ApplicationContextAware semantics.

Parameters
applicationContext the applicationContext to set

Protected Methods

protected void springTestContextAfterTestClass ()

Delegates to the configured TestContextManager to call 'after test class' callbacks.

Throws
Exception if a registered TestExecutionListener throws an exception

protected void springTestContextAfterTestMethod (Method testMethod)

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
Exception allows all exceptions to propagate

protected void springTestContextBeforeTestClass ()

Delegates to the configured TestContextManager to call 'before test class' callbacks.

Throws
Exception if a registered TestExecutionListener throws an exception

protected void springTestContextBeforeTestMethod (Method testMethod)

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
Exception allows all exceptions to propagate.

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.

Throws
Exception if a registered TestExecutionListener throws an exception