Java News from Wednesday, December 5, 2007

JBoss has posted a beta of JSFUnit 1.0, a unit testing framework for Java Server Faces based on based on Cactus and JUnit.

JSFUnit tests run inside the container, which provides the developer full access to managed beans, the FacesContext, EL Expressions, and the internal JSF component tree. At the same time, you also have access to parsed HTML output of each client request.

After each faces request, you get access to the full internal state of your application through the FacesContext. With the FacesContext in hand, you have the keys to the kingdom. Between the JSF API and the JSFUnit helper classes, you can see what "really happened" after each request. You can also make additional HTTP requests to simulate a user session. And, since your application is fully deployed, you can assert state at any level of abstraction all the way from the client HTML down to your database.

The typical usage pattern of JSFUnit is to programatically submit an http request and examine both the parsed HTML output and the JSF internals. JSFUnit makes this very easy to do.