Using HttpUnit to Perform Complex Assertions

Problem

You want to use HttpUnit to perform complex assertions on the returned result.

Solution

Implement an endXXX(com.meterware.httpunit.WebResponse) method for a given testXXX( ) method.

Discussion

Cactus provides support for two endXXX(WebResponse) signatures. You, as the test writer, need to choose one of the method signatures. Cactus ensures that the correct method is invoked.

// write this method for the standard Cactus response
public void endXXX(org.apache.cactus.WebResponse) {
    // insert simple assertions
}

// or write this method to use HttpUnit
public void endXXX(com.meterware.httpunit.WebResponse) {
               // insert complex assertions
               }

These methods are executed on the client side JVM after the corresponding server side testXXX( ) method completes without throwing an exception.

See Also

For more information on how to use HttpUnit to perform complex assertions, see Chapter 5.

Get Java Extreme Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.