简体   繁体   中英

How to roll back Junits?

My project is pretty simple Java and Hibernate (- not Spring). When creating unit tests - Is there an easy way to roll back all the effects of the tests? or I have to do it manually?

I know that when using spring you can have the @Transactional annotation but I am not using Spring.

All you need to do is do start a transaction before each test and roll it back after each test. At least that's the way they do in Grails.

If you want to revert DB changes you should use a specific tool such as DBUnit where you can define your dataset and reset the status of the database for each single test.

You may clean the database either by defining your own @teardown or @before or by using DBUnit and annotate the methods with @DataSet specifying the dataset you wish to being used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM