Be careful wiping the world and starting a new one every time. Soon, you will most likely want to start with a โstandardโ set of test data downloaded to your system. Thus, you really need to return to this basic state before starting each test. In this case, before each test, you want a Transaction that performs a rollsback .
To accomplish this, you must annotate your JUnit class:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath:/path/to/spring-config.xml"}) @TransactionConfiguration(transactionManager="myTransactionManager", defaultRollback=true) public class MyUnitTestClass { ... }
And then annotate each of your test methods with @Transactional:
@Transactional @Test public void myTest() { ... }
Brad lee
source share