Simple classes to help test JSPs

JSP TEST is a collection of Java classes to help you test JSPs automatically.

Download the latest version (release 2) jsptest_r2.zip (66k including source and docs).

The classes run independently of any JSP servlet engine or web server because all they do is make HTTP requests, maintains cookies and stores the results of a request. You should use these classes with your favourite testing environment. I use JUnit.

A related project is Russell Gold's HTTPUnit at Sourceforge. I've not tried it properly yet, but HTTPUnit looks much more feature-rich than JSPTest, but is correspondingly more complex.

Background

The idea is that you can automatically run a suit of tests and be confident that your web site's logic is correct after any changes you make to code. The easy way to do this is to put a comment in your HTML/JSPs and then check that you can find that comment in the response sent back from the server for an appropriate request. In a real application you will also want to check cookie values and check that records have been created or updated in your database, etc.

The classes help you make http requests, but it's up to you to put the code in place to implement the checks on what you get back. Best if you look at the examples.

Warning: these classes can be thought of as a very simple and very incomplete HTTP client implementation. If you already have a HTTP client implementation, you may be better off using it rather than these classes. These classes have been built to make testing easy rather than built to be a complete HTTP client.

FAQ

  • Will this work with ASP? (XSP, CGIs, plain HTML, whatever)
    Should do. Try it.

  • Is this a load/stress testing tool?
    Nope.

  • Is this a GUI tester?
    Not really. You will probably separate application logic from display by putting your logic into beans or servlets, and use JSP to render information.
    However, chances are you may have some logic in a JSP or a servlet: examples might be deciding which page to forward to based on parameters supplied from the user — perhaps for user registration. Sure you can test your boolean isValidRegistration() method, but you will also want to test that isValidRegistration() is called correctly with the right parameters from the HTML form. This is where these classes come in. They allow you to call the JSP (servlet, whatever) and check that you get the right stuff coming back.
    You can catch these common problems:

    • Someone changes the names of the field on a form;

    • someone reworks a form and removes a field;

    • you add a required field to a piece of logic and it is missing from the form.


  • Isn't this just a HTTP client?
    Yes. A bad, bad, simple, incomplete HTTP client.
    If you have a good HTTP client that you know and trust, you're probably better off using it.

    Please don't try to use these classes in place of a good HTTP client: there's a lot that hasn't been implemented and a lot of simplifications. If you really need to test HTTP client/server communications, you probably don't want these classes. If you just want a quick way to send requests and make sure what you get back is roughly what you expect to get back, these classes may be for you.

Examples

  1. Example1.java shows the "hello world" case of using the testing classes.

  2. JSPTestTest.java shows two uses of these classes inside of JUnit.

Feedback

You can get the latest version of JSP Test from: http://www.dallaway.com/jsptest/

Mailing list

You can subscribe for the low-volume JSPTest announcement list to receive updates when new versions of JSPTest become available. No spam ever.

Changes

2000-08-18: Added Host: header to requests to support HTTP/1.1 virtual hosts.

last modified Monday, 26-Mar-2001 01:58:44 BST