类 SqlScriptsTestExecutionListener
- java.lang.Object
- org.springframework.test.context.support.AbstractTestExecutionListener
- org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener
- 所有已实现的接口:
Ordered
,TestExecutionListener
public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListener
TestExecutionListener
that provides support for executing SQLscripts
and inlinedstatements
configured via the@Sql
annotation.Scripts and inlined statements will be executed before or after execution of the corresponding test method, depending on the configured value of the
executionPhase
flag.Scripts and inlined statements will be executed without a transaction, within an existing Spring-managed transaction, or within an isolated transaction, depending on the configured value of
SqlConfig.transactionMode()
and the presence of a transaction manager.Script Resources
For details on default script detection and how script resource locations are interpreted, see
Sql.scripts()
.Required Spring Beans
A
PlatformTransactionManager
and aDataSource
, just aPlatformTransactionManager
, or just aDataSource
must be defined as beans in the SpringApplicationContext
for the corresponding test. Consult the javadocs forSqlConfig.transactionMode()
,SqlConfig.transactionManager()
,SqlConfig.dataSource()
,TestContextTransactionUtils.retrieveDataSource(org.springframework.test.context.TestContext, java.lang.String)
, andTestContextTransactionUtils.retrieveTransactionManager(org.springframework.test.context.TestContext, java.lang.String)
for details on permissible configuration constellations and on the algorithms used to locate these beans.- 从以下版本开始:
- 4.1
- 作者:
- Sam Brannen
- 另请参阅:
Sql
,SqlConfig
,SqlGroup
,TestContextTransactionUtils
,TransactionalTestExecutionListener
,ResourceDatabasePopulator
,ScriptUtils
字段概要
从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 SqlScriptsTestExecutionListener()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterTestMethod(TestContext testContext)
Execute SQL scripts configured via@Sql
for the suppliedTestContext
after the current test method.void
beforeTestMethod(TestContext testContext)
Execute SQL scripts configured via@Sql
for the suppliedTestContext
before the current test method.int
getOrder()
Returns5000
.从类继承的方法 org.springframework.test.context.support.AbstractTestExecutionListener
afterTestClass, beforeTestClass, prepareTestInstance
构造器详细资料
SqlScriptsTestExecutionListener
public SqlScriptsTestExecutionListener()
方法详细资料
getOrder
public final int getOrder()
Returns5000
.- 指定者:
getOrder
在接口中Ordered
- 覆盖:
getOrder
在类中AbstractTestExecutionListener
- 返回:
- the order value
- 另请参阅:
Ordered.HIGHEST_PRECEDENCE
,Ordered.LOWEST_PRECEDENCE
beforeTestMethod
public void beforeTestMethod(TestContext testContext) throws Exception
Execute SQL scripts configured via@Sql
for the suppliedTestContext
before the current test method.- 指定者:
beforeTestMethod
在接口中TestExecutionListener
- 覆盖:
beforeTestMethod
在类中AbstractTestExecutionListener
- 参数:
testContext
- the test context in which the test method will be executed; nevernull
- 抛出:
Exception
- allows any exception to propagate
afterTestMethod
public void afterTestMethod(TestContext testContext) throws Exception
Execute SQL scripts configured via@Sql
for the suppliedTestContext
after the current test method.- 指定者:
afterTestMethod
在接口中TestExecutionListener
- 覆盖:
afterTestMethod
在类中AbstractTestExecutionListener
- 参数:
testContext
- the test context in which the test method was executed; nevernull
- 抛出:
Exception
- allows any exception to propagate