类 AbstractTestNGSpringContextTests
- java.lang.Object
- org.springframework.test.context.testng.AbstractTestNGSpringContextTests
- 所有已实现的接口:
Aware
,ApplicationContextAware
,org.testng.IHookable
,org.testng.ITestNGListener
@TestExecutionListeners({ServletTestExecutionListener.class,DirtiesContextBeforeModesTestExecutionListener.class,DependencyInjectionTestExecutionListener.class,DirtiesContextTestExecutionListener.class,EventPublishingTestExecutionListener.class}) public abstract class AbstractTestNGSpringContextTests extends Object implements org.testng.IHookable, ApplicationContextAware
Abstract base test class which integrates the Spring TestContext Framework with explicitApplicationContext
testing support in a TestNG environment.Concrete subclasses should typically declare a class-level
@ContextConfiguration
annotation to configure the application contextresource 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 appropriateTestExecutionListeners
manually. Concrete subclasses must also have constructors which either implicitly or explicitly delegate tosuper();
.The following
TestExecutionListeners
are configured by default:- 从以下版本开始:
- 2.5
- 作者:
- Sam Brannen, Juergen Hoeller
- 另请参阅:
ContextConfiguration
,TestContext
,TestContextManager
,TestExecutionListeners
,ServletTestExecutionListener
,DirtiesContextBeforeModesTestExecutionListener
,DependencyInjectionTestExecutionListener
,DirtiesContextTestExecutionListener
,EventPublishingTestExecutionListener
,AbstractTransactionalTestNGSpringContextTests
,AbstractJUnit4SpringContextTests
字段概要
字段 修饰符和类型 字段 说明 protected ApplicationContext
applicationContext
TheApplicationContext
that was injected into this test instance viasetApplicationContext(ApplicationContext)
.protected Log
logger
Logger available to subclasses.
构造器概要
构造器 构造器 说明 AbstractTestNGSpringContextTests()
Construct a newAbstractTestNGSpringContextTests
instance and initialize the internalTestContextManager
for the current test class.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
run(org.testng.IHookCallBack callBack, org.testng.ITestResult testResult)
Delegates to the test method in the suppliedcallback
to execute the actual test and then tracks the exception thrown during test execution, if any.void
setApplicationContext(ApplicationContext applicationContext)
Set theApplicationContext
to be used by this test instance, provided viaApplicationContextAware
semantics.protected void
springTestContextAfterTestClass()
Delegates to the configuredTestContextManager
to call 'after test class' callbacks.protected void
springTestContextAfterTestMethod(Method testMethod)
Delegates to the configuredTestContextManager
to post-process the test method after the actual test has executed.protected void
springTestContextBeforeTestClass()
Delegates to the configuredTestContextManager
to call 'before test class' callbacks.protected void
springTestContextBeforeTestMethod(Method testMethod)
Delegates to the configuredTestContextManager
to pre-process the test method before the actual test is executed.protected void
springTestContextPrepareTestInstance()
Delegates to the configuredTestContextManager
to prepare this test instance prior to execution of any individual tests, for example for injecting dependencies, etc.
字段详细资料
applicationContext
@Nullable protected ApplicationContext applicationContext
TheApplicationContext
that was injected into this test instance viasetApplicationContext(ApplicationContext)
.
构造器详细资料
AbstractTestNGSpringContextTests
public AbstractTestNGSpringContextTests()
Construct a newAbstractTestNGSpringContextTests
instance and initialize the internalTestContextManager
for the current test class.
方法详细资料
setApplicationContext
public final void setApplicationContext(ApplicationContext applicationContext)
Set theApplicationContext
to be used by this test instance, provided viaApplicationContextAware
semantics.- 指定者:
setApplicationContext
在接口中ApplicationContextAware
- 参数:
applicationContext
- the ApplicationContext that this test runs in- 另请参阅:
BeanInitializationException
springTestContextBeforeTestClass
@BeforeClass(alwaysRun=true) protected void springTestContextBeforeTestClass() throws Exception
Delegates to the configuredTestContextManager
to call 'before test class' callbacks.- 抛出:
Exception
- if a registered TestExecutionListener throws an exception
springTestContextPrepareTestInstance
@BeforeClass(alwaysRun=true, dependsOnMethods="springTestContextBeforeTestClass") protected void springTestContextPrepareTestInstance() throws Exception
Delegates to the configuredTestContextManager
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
springTestContextBeforeTestMethod
@BeforeMethod(alwaysRun=true) protected void springTestContextBeforeTestMethod(Method testMethod) throws Exception
Delegates to the configuredTestContextManager
to pre-process the test method before the actual test is executed.- 参数:
testMethod
- the test method which is about to be executed- 抛出:
Exception
- allows all exceptions to propagate
run
public void run(org.testng.IHookCallBack callBack, org.testng.ITestResult testResult)
Delegates to the test method in the suppliedcallback
to execute the actual test and then tracks the exception thrown during test execution, if any.- 指定者:
run
在接口中org.testng.IHookable
- 另请参阅:
IHookable.run(IHookCallBack, ITestResult)
springTestContextAfterTestMethod
@AfterMethod(alwaysRun=true) protected void springTestContextAfterTestMethod(Method testMethod) throws Exception
Delegates to the configuredTestContextManager
to post-process the test method after the actual test has executed.- 参数:
testMethod
- the test method which has just been executed on the test instance- 抛出:
Exception
- allows all exceptions to propagate
springTestContextAfterTestClass
@AfterClass(alwaysRun=true) protected void springTestContextAfterTestClass() throws Exception
Delegates to the configuredTestContextManager
to call 'after test class' callbacks.- 抛出:
Exception
- if a registered TestExecutionListener throws an exception