Designing Testable JSPs
Problem
Designing JSPs to be testable outside of a running server.
Solution
Write your JSPs to use helper classes that do not depend on a running server, and then test those helper classes with JUnit.
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.
See Also
Recipe 7.15 discusses testing non-server-dependent classes.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access