7.16 Designing Testable JSPs

7.16.1 Problem

Designing JSPs to be testable outside of a running server.

7.16.2 Solution

Write your JSPs to use helper classes that do not depend on a running server, and then test those helper classes with JUnit.

7.16.3 Discussion

Testing server code is challenging, as we have seen throughout this chapter. JSPs pose a greater risk of failure because multiple technologies are intermingled. JSPs mix snippets of Java code with snippets of HTML, XML, JSTL, and JavaBeans; add the deployment of JSP and the problems of testing only get worse. A better approach to designing and testing JSPs is to write support classes that do not depend on a running server to perform logic. These support classes can then be tested outside of a running server using JUnit.

7.16.4 See Also

Recipe 7.15 discusses testing non-server-dependent classes.