类 TestTransaction
- java.lang.Object
- org.springframework.test.context.transaction.TestTransaction
public class TestTransaction extends Object
TestTransactionprovides a collection of static utility methods for programmatic interaction with test-managed transactions within test methods, before methods, and after methods.Consult the javadocs for
TransactionalTestExecutionListenerfor a detailed explanation of test-managed transactions.Support for
TestTransactionis automatically available whenever theTransactionalTestExecutionListeneris enabled. Note that theTransactionalTestExecutionListeneris typically enabled by default, but it can also be manually enabled via the@TestExecutionListenersannotation.- 从以下版本开始:
- 4.1
- 作者:
- Sam Brannen
- 另请参阅:
TransactionalTestExecutionListener
构造器概要
构造器 构造器 说明 TestTransaction()
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static voidend()Immediately force a commit or rollback of the current test-managed transaction, according to the rollback flag.static voidflagForCommit()Flag the current test-managed transaction for commit.static voidflagForRollback()Flag the current test-managed transaction for rollback.static booleanisActive()Determine whether a test-managed transaction is currently active.static booleanisFlaggedForRollback()Determine whether the current test-managed transaction has been flagged for rollback or flagged for commit.static voidstart()Start a new test-managed transaction.
构造器详细资料
TestTransaction
public TestTransaction()
方法详细资料
isActive
public static boolean isActive()
Determine whether a test-managed transaction is currently active.
isFlaggedForRollback
public static boolean isFlaggedForRollback()
Determine whether the current test-managed transaction has been flagged for rollback or flagged for commit.- 返回:
trueif the current test-managed transaction is flagged to be rolled back;falseif the current test-managed transaction is flagged to be committed- 抛出:
IllegalStateException- if a transaction is not active for the current test- 另请参阅:
isActive(),flagForRollback(),flagForCommit()
flagForRollback
public static void flagForRollback()
Flag the current test-managed transaction for rollback.Invoking this method will not end the current transaction. Rather, the value of this flag will be used to determine whether or not the current test-managed transaction should be rolled back or committed once it is ended.
- 抛出:
IllegalStateException- if no transaction is active for the current test- 另请参阅:
isActive(),isFlaggedForRollback(),start(),end()
flagForCommit
public static void flagForCommit()
Flag the current test-managed transaction for commit.Invoking this method will not end the current transaction. Rather, the value of this flag will be used to determine whether or not the current test-managed transaction should be rolled back or committed once it is ended.
- 抛出:
IllegalStateException- if no transaction is active for the current test- 另请参阅:
isActive(),isFlaggedForRollback(),start(),end()
start
public static void start()
Start a new test-managed transaction.Only call this method if
end()has been called or if no transaction has been previously started.- 抛出:
IllegalStateException- if the transaction context could not be retrieved or if a transaction is already active for the current test- 另请参阅:
isActive(),end()
end
public static void end()
Immediately force a commit or rollback of the current test-managed transaction, according to the rollback flag.- 抛出:
IllegalStateException- if the transaction context could not be retrieved or if a transaction is not active for the current test- 另请参阅:
isActive(),start()