I am testing DAO in Spring Application.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/applicationContext.xml")
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional
public class CommentDAOImplTest { @Autowired //testing mehods here}
The tests are running good. Iam able to add an comment and I also have a defaultRollback property set. So, the added comment will be deleted automatically. happy!..Now the problem is with the sequence number for mcomment. Can I, in any way rollback the seq number? any suggestins on that. I dont want to mess up the sequrnce number. Business requires comment Id to be showed. (I still dont know why).
I know in memory db is an option....but I am guessing defaultRollback purpose is to eliminate in memory db testing and mocking. (Just my opinion.)
Create a test database which you wipe before you start the tests.
Do not run tests in the production database (might accidentally insert test data into production) and never copy production into test database (this would be a strong indication that you have no idea what you're testing and that testing is an afterthought at best).