Information Technology Reference
In-Depth Information
DatabaseTestCase.assertNotNull("data set file was null", fileName);
return DBUnitHibernateConfigurator.getDataSet(fileName);
}
protected abstract String getDBUnitDataSetFileForSetUp();
}
A sample resulting test case that implements DefaultDBUnit-
HibernateTestCase is shown in Listing 6-22.
LISTING 6-22
The New Test Case in Action
public class WordDAOImplTest extends DefaultDBUnitHibernateTestCase {
public void testUpdateWordSpelling() throws Exception{
WordDAOImpl dao = new WordDAOImpl();
IWord wrd = dao.findWord("pugnacious");
wrd.setSpelling("pugnacious-ness");
dao.updateWord(wrd);
IWord wrd2 = dao.findWord("pugnacious-ness");
assertEquals("should be id of 1", 1, wrd2.getId());
}
public void testFindVerifyDefinitionsSize() throws Exception{
WordDAOImpl dao = new WordDAOImpl();
IWord wrd = dao.findWord("pugnacious");
Set defs = wrd.getDefinitions();
assertEquals("size should be one", 1, defs.size());
}
protected String getDBUnitDataSetFileForSetUp() {
return "words-seed.xml";
}
public WordDAOImplTest(String name) {
super(name);
}
}
DbUnit offers an API (as shown earlier) that can be utilized effec-
tively via composition, which creates enormous opportunities for pow-
erful combination frameworks, too. With this added flexibility, testing
various architectures at different layers becomes quite easy. For exam-
ple, developer testing of Struts applications can be challenging. A
common tactic is to utilize a framework like HttpUnit, which simulates
Search WWH ::




Custom Search