Get current Spring transaction in JUnit and commit it
问题 is it possible to get current Spring transaction in JUnit? I want to test JPA in DAO. And DAO do not have transactions. In tests spring create transaction for every method. I want transaction to be commited somewhere in the middle of test. Need it to test DB status. Only solution I found is to create @Rule for every method. 回答1: You can use TestTransaction in order to manage spring test transactions: TestTransaction.flagForCommit(); TestTransaction.end(); This will flag the current