Appendix A. Complete solutions

 

Here you can find complete solutions to some of the problems we raise in the recipes. We did not want to confuse these recipes with code samples that are hundreds of lines long, but we thought it important to include the complete solutions, so we have done so here. Consult table A.1 to see the recipes to which these solutions correspond.

Table A.1. The complete solutions, and the recipes to which they correspond

Complete solution

Follow up to recipe

A.1—Define a test in XML 4.9—Define a test suite in XML
A.2—Parameterized Test Case overriding runTest() 4.8—Build a data-driven test suite
A.3—Ignore the order of elements in an XML document 9.2—Ignore the order of elements in an XML document
A.4—Test an XSL stylesheet in isolation 9.6—Test an XSL stylesheet in isolation
A.5—Validate XML documents in your tests 9.7—Validate XML documents in your tests
A.6—Aspect-based universal Spy 14.6—Test a Template Method’s implementation
A.7—Test a BMP entity bean 11.6—Test a BMP entity bean

A.1. Define a test suite in XML

Solution

We first present the Parameterized Test Case that tests the split() method. The custom test suite method in listing A.1 specifies the location of the XML document containing the test data.

Listing A.1. AllocateMoneyXmlBasedTest

Next is the code for the object that builds the tests by parsing an XML document, and converting each test element into an AllocateMoneyTest object.

Listing A.2. AllocateMoneyTestBuilder

A.2. Parameterized Test Case overriding runTest()

A.3. Ignore the order of elements in an XML document

A.4. Test an XSL stylesheet in isolation

A.5. Validate XML documents in your tests

A.6. Aspect-based universal Spy

A.7. Test a BMP entity bean