@TestExecutionListeners(value={DependencyInjectionTestExecutionListener.class,DirtiesContextTestExecutionListener.class}) public abstract class AbstractTestNGSpringContextTests extends java.lang.Object implements ApplicationContextAware
ApplicationContext
testing support in a TestNG
environment.
Concrete subclasses:
@ContextConfiguration
annotation to configure the application context
resource locations
or annotated 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.super();
.TestContext
,
TestContextManager
,
TestExecutionListeners
,
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
|
private TestContextManager |
testContextManager |
private java.lang.Throwable |
testException |
Constructor and Description |
---|
AbstractTestNGSpringContextTests()
Construct a new AbstractTestNGSpringContextTests instance and initialize
the internal
TestContextManager for the current test. |
Modifier and Type | Method and Description |
---|---|
void |
run(IHookCallBack callBack,
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. |
protected final Log logger
protected ApplicationContext applicationContext
ApplicationContext
that was injected into this test instance
via setApplicationContext(ApplicationContext)
.private final TestContextManager testContextManager
private java.lang.Throwable testException
public AbstractTestNGSpringContextTests()
TestContextManager
for the current test.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 to setBeanInitializationException
protected void springTestContextBeforeTestClass() throws java.lang.Exception
TestContextManager
to call
'before test class'
callbacks.java.lang.Exception
- if a registered TestExecutionListener throws an
exceptionprotected void springTestContextPrepareTestInstance() throws java.lang.Exception
TestContextManager
to
prepare
this test
instance prior to execution of any individual tests, for example for
injecting dependencies, etc.java.lang.Exception
- if a registered TestExecutionListener throws an
exceptionprotected void springTestContextBeforeTestMethod(java.lang.reflect.Method testMethod) throws java.lang.Exception
TestContextManager
to
pre-process
the test method before the actual test is executed.testMethod
- the test method which is about to be executed.java.lang.Exception
- allows all exceptions to propagate.public void run(IHookCallBack callBack, ITestResult testResult)
test
method
in the supplied callback
to execute the actual test
and then tracks the exception thrown during test execution, if any.org.testng.IHookable#run(org.testng.IHookCallBack,
org.testng.ITestResult)
protected void springTestContextAfterTestMethod(java.lang.reflect.Method testMethod) throws java.lang.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 instancejava.lang.Exception
- allows all exceptions to propagateprotected void springTestContextAfterTestClass() throws java.lang.Exception
TestContextManager
to call
'after test class'
callbacks.java.lang.Exception
- if a registered TestExecutionListener throws an
exception