java - Spring Junit Database rollback at the end of test class -


i have lot of existing spring junit tests. tests extends abstract test class. public class servicetest extends abstractservicetest { in abstract class reinitialize database. reinitialize database on each test class

@before @override public void initglobal() throws exception {     initdatabase();     ... } 

i asking how can rollback on test class in end of execution of tests ? can initialize database 1 time , rollback changes in every test class

i think having 2 profiles better option 1 testing , other 1 development , on testing profile use memory based database h2 (here example) , on development profile use main database

when running tests use testing profile.instead of doing rolling or deleting data each time run test

if want use real database in unit tests totally discourage it.you can use spring test runner annotate class , rollback transactions

@runwith(springjunit4classrunner.class) @transactionconfiguration(defaultrollback=true) public class yourtestclass {      @test     @transactional     public void mytestmethod() {         // db rolled @ end of test     } } 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -