@TestExecutionListeners(value={ServletTestExecutionListener.class,DirtiesContextBeforeModesTestExecutionListener.class,ApplicationEventsTestExecutionListener.class,DependencyInjectionTestExecutionListener.class,DirtiesContextTestExecutionListener.class,EventPublishingTestExecutionListener.class}) public abstract class AbstractTestNGSpringContextTests extends Object implements org.testng.IHookable, ApplicationContextAware
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. 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. Concrete subclasses must also have
constructors which either implicitly or explicitly delegate to super();
.
This class explicitly registers the following TestExecutionListener
implementations. If you want to switch to using the default set of
listeners, see the class-level Javadoc for
@TestExecutionListeners
for details.
ContextConfiguration
,
TestContext
,
TestContextManager
,
TestExecutionListeners
,
ServletTestExecutionListener
,
DirtiesContextBeforeModesTestExecutionListener
,
ApplicationEventsTestExecutionListener
,
DependencyInjectionTestExecutionListener
,
DirtiesContextTestExecutionListener
,
EventPublishingTestExecutionListener
,
AbstractTransactionalTestNGSpringContextTests
,
AbstractJUnit4SpringContextTests
Modifier and Type | Field and Description |
---|---|
protected ApplicationContext |
applicationContext
The
ApplicationContext that was injected into this test instance
via setApplicationContext(ApplicationContext) . |
protected Log |
logger
Logger available to subclasses.
|
Constructor and Description |
---|
AbstractTestNGSpringContextTests()
Construct a new
AbstractTestNGSpringContextTests instance and initialize
the internal TestContextManager for the current test class. |
Modifier and Type | Method and Description |
---|---|
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(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(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. |
protected final Log logger
@Nullable protected ApplicationContext applicationContext
ApplicationContext
that was injected into this test instance
via setApplicationContext(ApplicationContext)
.public AbstractTestNGSpringContextTests()
AbstractTestNGSpringContextTests
instance and initialize
the internal TestContextManager
for the current test class.public final void setApplicationContext(ApplicationContext applicationContext)
ApplicationContext
to be used by this test instance,
provided via ApplicationContextAware
semantics.setApplicationContext
in interface ApplicationContextAware
applicationContext
- the ApplicationContext that this test runs inBeanInitializationException
@BeforeClass(alwaysRun=true) protected void springTestContextBeforeTestClass() throws Exception
TestContextManager
to call
'before test class' callbacks.Exception
- if a registered TestExecutionListener throws an exception@BeforeClass(alwaysRun=true, dependsOnMethods="springTestContextBeforeTestClass") protected void springTestContextPrepareTestInstance() throws Exception
TestContextManager
to
prepare this test
instance prior to execution of any individual tests, for example for
injecting dependencies, etc.Exception
- if a registered TestExecutionListener throws an exception@BeforeMethod(alwaysRun=true) protected void springTestContextBeforeTestMethod(Method testMethod) throws Exception
TestContextManager
to
pre-process
the test method before the actual test is executed.testMethod
- the test method which is about to be executedException
- allows all exceptions to propagatepublic void run(org.testng.IHookCallBack callBack, org.testng.ITestResult testResult)
callback
to execute the actual test
and then tracks the exception thrown during test execution, if any.run
in interface org.testng.IHookable
IHookable.run(IHookCallBack, ITestResult)
@AfterMethod(alwaysRun=true) protected void springTestContextAfterTestMethod(Method testMethod) throws Exception
TestContextManager
to
post-process the test method after the actual test has executed.testMethod
- the test method which has just been executed on the
test instanceException
- allows all exceptions to propagate@AfterClass(alwaysRun=true) protected void springTestContextAfterTestClass() throws Exception
TestContextManager
to call
'after test class' callbacks.Exception
- if a registered TestExecutionListener throws an exception