I want to start the database transactions before start of any test method and rollback all transactions at the end of running all tests.
How to do thing?What annotations should I use ?
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/testApplicationContext.xml"})
public class MyTests{
public void setUp(){
//Insert temporary data to Database
}
@Test
public void testOne(){
//Do some DB transactions
}
@Test void testTwo(){
//Do some more DB transactions
}
public void tearDown(){
//Need to rollback all transactions
}
}
Use @Before to launch method before any test and @After to launch method after every test. Use @Transactional spring’s annotation over a method or over a class to start transaction and @Rollback to rollback everything done in transaction.
Also there is same issue solved in another way.