TestNG + Spring 2.5

First of all, you need a dataSource bean at your applicationContext.xml:










Write a class that allows you to test database code (test your DAO's, mappings or your persistence layer methods). Transaction is rolled back at the end of test method.


@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class SimpleTest extends AbstractTransactionalTestNGSpringContextTests
{
@Test
public void test()
{
// applicationContext is injected and using contactDAO
// you can save Contact objects to DB in a database transaction
ContactDAO contactDAO = applicationContext.getBean("contactDAO");
contactDAO.save(new Contact());

List contacts = contactDAO.findAll();
assert CollectionsUtils.isNotEmpty(contacts);
}
}


Read Appendix B of Sping in Action, 2nd Edition, Manning for more details (perharps you need to commit test changes, find out how to do it there...).
0