Information Technology Reference
In-Depth Information
Automate Component Tests
Component or subsystem tests verify portions of a system and may
require a fully installed system or some external dependencies, such as
databases, file systems, or network endpoints, to name a few. These
tests verify that components interact to produce the expected aggregate
behavior. A typical component test requires the underlying database to
be running and may even cross architectural boundaries. Because
larger amounts of code are exercised by each test case, more code cov-
erage is obtained per test, and therefore, these tests tend to run longer
than unit tests.
Listing 6-3 presents a sample component test that utilizes the
DbUnit framework to seed a database, and then attempts to find data
based on the contents of the database. DbUnit uses XML files, which it
reads and then inserts the corresponding data into matching database
tables.
LISTING 6-3
Component Test Using DbUnit
public class DefaultWordDAOImplTest extends DatabaseTestCase {
protected IDataSet getDataSet() throws Exception {
return new FlatXmlDataSet(new File("test/conf/wseed.xml"));
}
protected IDatabaseConnection getConnection() throws Exception {
final Class driverClass =
Class.forName("org.gjt.mm.mysql.Driver");
final Connection jdbcConnection =
DriverManager.getConnection(
"jdbc:mysql://localhost/words",
"words", "words");
return new DatabaseConnection(jdbcConnection);
}
public void testFindVerifyDefinition() throws Exception{
final WordDAOImpl dao = new WordDAOImpl();
final IWord wrd = dao.findWord("pugnacious");
for(Iterator iter =
wrd.getDefinitions().iterator();
iter.hasNext();){
IDefinition def = (IDefinition)iter.next();
TestCase.assertEquals(
"def is not Combative in nature; belligerent.",
"Combative in nature; belligerent.",
def.getDefinition());
}
}
 
Search WWH ::




Custom Search