Unit Tests
From Taylor
Various types of JUnit tests are generated: Jpa, Service, Seam, Bpm, Pageflow, etc.
taylor-jboss-embedded is used to initialize the embedded JBoss and Seam containers using the generated descriptors. This provides the ContainerTestCase and Bootstrap classes to simplify initialization.
NOTE: taylor-jboss-embedded contains a port of the Seam TestNG classes to JUnit.
Additional base test classes are provided by taylor-commons, such as JpaCrudTest and SeamCrudTest.
Contents |
JPA
A JUnit test is generated for each Entity Bean in the jpa project.
- Implement the initData() method to initialize the database with related data.
- Implement the prePersist() method to initialize the entity.
public class TicketTest extends JpaCrudTest<Ticket> {
...
/** @generated */
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new TicketTest("testCrud"));
return new Bootstrap(suite);
}
...
/** @generated */
protected void initData(EntityManager em) throws Exception {
}
/** @generated */
protected void prePersist(EntityManager em) throws Exception {
entity = new Ticket();
entity.setTitle("Test Ticket");
entity.setOwner("user");
}
...
}
Service
A JUnit test is generated for each Session Bean in the ejb project. The order that the operations are defined in the interface dictates the order in which the test methods are executed. (See the Modify Code section for more on tweaking the code)
There is one method that is generated that is intended to be changed. This is the create() method used to initialize the entity bean that is being tested. For a basic service with default save, get, query, and delete operation, this is the only method that would need to be implemented for a positive test case.
public class TicketServiceTest extends ContainerTestCase {
...
/** @generated */
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new TicketServiceTest("testSave"));
suite.addTest(new TicketServiceTest("testGet"));
suite.addTest(new TicketServiceTest("testQuery"));
suite.addTest(new TicketServiceTest("testDelete"));
return new Bootstrap(suite);
}
...
private void create() {
entity = new Ticket();
entity.setTitle("service test ticket");
entity.setOwner("user");
}
...
}
Seam
A Seam junit test is generated in the Jsf project for each entity. These tests verify that the Finder and Editor components are working properly.
- You might need to tweak the default values for properties.
public class TicketSeamTest extends SeamCrudTest<Ticket> {
...
/** @generated */
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new TicketTest("testCrud"));
return new Bootstrap(suite);
}
...
/** @generated */
protected void initData(EntityManager em) throws Exception {
...
}
...
}
QA
A FaceletRenderTest is generated in the QA project. This test uses Cargo to start the JBoss server and JSFUnit to execute each facelets page.
This is a basic so-called idiot test that simply opens every page to ensure that they do not blow up on first entry, but does no functional testing.
The base test class is found in taylor-results.
public class FaceletRenderTest extends BaseFaceletRenderTest {
/** @generated */
public FaceletRenderTest(String name) {
super(name);
}
/** @generated */
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new FaceletRenderTest("testTicket"));
return suite;
}
/** @generated */
public void testTicket() throws Exception {
super.doTest("Ticket");
}
}
Code Coverage
The Cobertura Test Coverage Maven Report is generated into the project's pom.xml. Use this report to ensure you are getting enough test coverage.
To run the report type this at the command line:
mvn clean site

