@TestExecutionListeners(value={ServletTestExecutionListener.class,DirtiesContextBeforeModesTestExecutionListener.class,DependencyInjectionTestExecutionListener.class,DirtiesContextTestExecutionListener.class}) public abstract class AbstractTestNGSpringContextTests extends java.lang.Object implements org.testng.IHookable, 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();
.The following TestExecutionListeners
are configured by default:
ContextConfiguration
,
TestContext
,
TestContextManager
,
TestExecutionListeners
,
ServletTestExecutionListener
,
DirtiesContextBeforeModesTestExecutionListener
,
DependencyInjectionTestExecutionListener
,
DirtiesContextTestExecutionListener
,
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(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
@Nullable protected ApplicationContext applicationContext
ApplicationContext
that was injected into this test instance
via setApplicationContext(ApplicationContext)
.public AbstractTestNGSpringContextTests()
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 java.lang.Exception
TestContextManager
to call
'before test class' callbacks.java.lang.Exception
- if a registered TestExecutionListener throws an exception@BeforeClass(alwaysRun=true, dependsOnMethods="springTestContextBeforeTestClass") protected 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 exception@BeforeMethod(alwaysRun=true) protected 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 executedjava.lang.Exception
- 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(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 propagate@AfterClass(alwaysRun=true) protected void springTestContextAfterTestClass() throws java.lang.Exception
TestContextManager
to call
'after test class' callbacks.java.lang.Exception
- if a registered TestExecutionListener throws an exception