JspTest lets unit tests compile JavaServer Pages into servlet classes and invoke them without deploying to a full web container. Extend HtmlTestCase to render a JSP with a simulated request and check its HTML output. section 5.3.1 section 5.5
A small setup gets JSP tests ready:
- Create a shared HtmlTestCase subclass and override getWebRoot so tests can use short JSP paths. section 5.3.1
- Render the page, then assert that its login form contains the expected fields and submit button. section 5.3.1
import net.sf.jsptest.HtmlTestCase;
public abstract class MyJspTestCase extends HtmlTestCase {
@Override
protected String getWebRoot() {
return "./websrc/jsp";
}
}
This base class points JspTest at the JSP directory, so tests can request pages by shorter paths. section 5.3.1
Listing 5.16. Making use of our abstract JspTest base class
A login-page test checks for the username, password, and submit controls. section 5.3.1
