Dovetail Testing Reference

Kevin Gilpin
Last Updated...



Most JSP pages are very fragile. It is very difficult to write good automated tests for JSP pages, and it is very easy to make changes to pages which introduce bugs without causing compilation errors. One of the primary goals of Dovetail is to make it much easier to write robust, testable web sites using JSP.

Brittleness of JSP

The brittleness of JSP is primarily due to:
  1. Loose linkage between JSP pages. There is no way to check or enforce that a link is valid.
  2. Loose binding between pages and stored data. Data is typically stored using string-value keys using methods like HttpSession#setAttribute and ServletRequest#setAttribute. If one part of an application decides to change the String key by which a value is stored, all other pages that reference that value must be located and changed as well. There is no compile-time checking to verify that session or request attributes are being correctly accessed.
Dovetail solves problem (1) by providing the link element. And it solves problem (2) by generating Java code which contains statically compiled and typed methods for accessing all types of data used by the JSP application.

Difficulty of Writing Automated Tests of JSP Pages

The JSP/Servlet architecture is difficult to test. The output of a JSP page is generally HTML, which is rendered by a browser. Correctness of the JSP pages can be tested by parsing through the generated HTML, but this is a very difficult and fragile process. Even the smallest change to the JSP page, such as the introduction of a new table, can break automated tests. Furthermore, the primary mode of submitting data to a JSP page is through an HTTP request (a GET with a query string, or a form POST). There is no easy or obvious way to write automated tests using HTTP. Furthermore, the run-time architecture of a JSP/Servlet application is very unweildy; even running the simplest test incurs the overhead of starting up a JSP page compiler, web server, and potentially an application server.

The Dovetail Solution

Dovetail largely solves the problem of JSP testability by cleanly separating the Model and Controller aspects of an application from its View. (For an explanation of the benefits of a Model View Conroller architecture, try here). Dovetail uses the Site and Schema documents to cleanly separate separates all of logic in a JSP application from the page rendering. This allows almost all of the behavior of a site to be tested independently from the JSP framework. Tests can be written using a simple declarative XML language, or using Java code. The HTTP protocol and the application server are removed from the picture completely. Using Dovetail will bring you great benefits in terms of ease of writing tests and rapidity of debugging.

Index of Elements


Element suite

A test 'suite' is an XML document which consists of some header information and a series of page-tests. The tests within a suite are all run within a single user session context, so they can rely on having common session data. For instance, if the first page-test logs in a user and stores the userID in the session, subsequent page-tests can rely on the userID being present in the session.

One or more tests may be easily run using the Dovetail test suite interpreter, according to the following example:
c:\myproject> java -cp <classpath> agonism.dovetail.test.Suite c:\java\dovetail\schema\test.qjml 
                   test-suite-1.xml test-suite-1.xml ...
where each test-suite-i.xml is an XML document which conforms to the Test DTD, and <classpath> includes all the JAR files in the Dovetail lib directory.

suite attributes
NameDescriptionRequiredDefault Value
siteName The name of the site, as specified in the site element of the Site XML document. true
siteClass The name of the Java class has been generated by Dovetail to implement the Site. See the section Generated Site Java Code for details on this class (including what its name is). true
schemaName The name of the database schema, as specified in the schema element of the Schema XML document. true
schemaClass The name of the Java class has been generated by Dovetail to implement the database schema. See the section Generated DB Schema Java Code for details on this class (including what its name is). true

suite child elements
page-test The test suite consists primarily of a series of page-tests, each of which exercises the functionality of a single page in the site. 0*

Element page-test

Each page-test exercises the functionality of a single page the site. The page-test may test the values returned from query elements in the page, or it may submit a form.

page-test attributes
NameDescriptionRequiredDefault Value
pageName Name of the page within the site that will be tested. true

page-test child elements
description Describes the purpose of the test. 01
parameter-value Used to specify values for the page parameters. 0*
query-test Each query-test can execute and test the results of a query which was defined on the page.

Either query-test or form-test elements may be in a page-test, but not both.
form-test A form-test is used to submit values for the form-element in a form, and process the resulting actions.

Either query-test or form-test elements may be in a page-test, but not both.