Information Technology Reference
In-Depth Information
public DefaultWordDAOImplTest(String name) {
super(name);
}
}
Component-level tests use more dependencies than unit tests, but
still not necessarily as many as higher-level system tests (defined
shortly). Component-level tests exercise code via an API, but these
may or may not be exposed to clients. In Listing 6-3, an object in a
Data Access Object (DAO) layer is essentially tested via an exposed
interface. Another example of a component test is exercising an action
class in a Struts architecture via the StrutsTestCase framework, as
shown in Listing 6-4. This test obviously requires a database to be run-
ning; however, the Web container is mocked out and the API exercised
isn't necessarily exposed to clients.
In Listing 6-4, the StrutsTestCase framework has been combined
with DbUnit to provide both a database seeding functionality and a
mock container. The DeftMeinMockStrutsTestCase class is a template,
which requires that the getDBUnitDataSetFileForSetUp method be
implemented.
LISTING 6-4
Component Test Using StrutsTest
public class ProjectViewActionTest extends DeftMeinMockStrutsTestCase {
public void testProjectViewAction() throws Exception {
this.addRequestParameter("projectId", "100");
this.setRequestPathInfo("/viewProjectHistory");
this.actionPerform();
this.verifyForward("success");
Project project = (Project)this.getRequest()
.getAttribute("project");
assertNotNull(project);
assertEquals(project.getName(), "DS");
}
protected String getDBUnitDataSetFileForSetUp() {
return "dbunit-seed.xml";
}
public ProjectViewActionTest(String name) {
super(name);
}
}
Search WWH ::




Custom Search