InfoQ

News

JSF Testing Tools

Posted by Srini Penchikala on Dec 31, 2007

Community
Java
Topics
Open Source ,
Artifacts & Tools ,
Unit Testing
Tags
JSFUnit ,
Shale Test ,
Frameworks ,
Testing

Unit testing JSF based web applications has been considered difficult because of the constraints of testing JSF components outside the container. Most of the web-tier testing frameworks follow black-box testing approach where developers write test classes using the web components to verify the rendered HTML output is what is expected. Frameworks such as HtmlUnit, HttpUnit, Canoo WebTest, and Selenium fall into this category. The limitation of these frameworks is that they only test the client side of a web application.

But this trend is changing with the recently released JSFUnit and other JSF testing frameworks such as Shale Test and JSF Extensions that support white-box testing to test both client and server components of the web application. And projects like Eclipse Web Tools Platform (WTP) and JXInsight are also helping in the development and testing of JSF applications.

Like any other unit testing framework, a typical JSF test framework should provide the following features:

  • Ability to run a test case in isolation, outside the container and from within an IDE like Eclipse or NetBeans to promote Test Driven Development (TDD).
  • Ability to test full HTTP Request-Response lifecycle.
  • Integration with build tools such as Ant or Maven to run unit tests in an automated build and Continuous Integration environment.

The test framework should also support the JSF specific requirements like:

  • Use JSF API calls in the test methods instead of checking HTML output or client-side DOM object.
  • Navigation testing by validating the user input on the form and access the proper page view.
  • Verify that actions perform as expected and error conditions produce expected error messages.
  • Validation of JSF components even when the "rendered" attribute is set to false (where the component is not rendered on the web browser but still has state on the server side).
  • Verify that the XML configuration files (faces-config.xml etc) are loaded correctly.
Testing Frameworks

JSFUnit, which is built on HttpUnit and Apache Cactus, allows integration testing and debugging of JSF applications and JSF AJAX components. It can be used for testing both client and server side JSF artifacts in the same test class. With JSFUnit API, the test class methods can submit data on a form and verify that managed beans are properly updated.

JSFUnit includes a JSF Static Analysis test suite to validate the JSF configuration files to identify any configuration related issues before they occur at run-time. It also provides JSFTimer component for performance analysis of the JSF lifecycle. This can be used to trace the response time for each phase of the JSF lifecycle for a given web request and assert that the response time is within SLA limits.

JSFUnit includes support for RichFaces and Ajax4jsf components. Beta 1 version of this framework was released last month and the second Beta Version release is scheduled for the end of next month.

Shale Test Framework, an Apache project, provides mock object implementations for Servlet and JSF components. These base test classes can be used for testing Shale framework classes as well as JSF application components built on top of the framework. Shale Test can be used to write isolated unit tests that exercise the methods exposed by ViewController interface. This is useful because of the complexity involved in setting up the runtime environment for a ViewController component. Following are the main classes in Shale Test framework:

Shale Test also has integration with Spring Framework to allow a JSF component to be bound as a managed bean or as a Spring bean.

JSF Extensions project is a collection of non-UI components that extend the functionality of a JSF 1.2 based web application. It uses JUnit, HTMLUnit, and Cactus for automated testing. Test-Time module of the framework provides mock objects for JSF 1.2 components. Design-Time module has a JSF hot-deploy feature to stop and restart the application without going through build & redeploy cycles. This feature, based on JSF PhaseListener interface, causes all the configuration files and classes to be reloaded. This allows the developers to follow a test driven iterative JSF development approach when writing JSF applications.

Tools

There are also some development tools that aid in the development and performance monitoring of JSF applications. JXInsight from JInspired group provides a JSF trace and profile feature which is based on the PhaseListener interface. By including this tracing phase listener in the JSF application, developers and web administrators can collect information such as trace stacks, java call stacks and runtime UIComponent hierarchy associated with a JSF request.

JSF tools sub-project in Eclipse WTP project also provides tool support for developing and deploying JSF based web applications with features such as Visual JSF Page Editor and Faces Config Editor.

mocks vs. stubs by Dennis Byrne Posted Dec 31, 2007 12:39 PM
JXInsight JSF AspectJ Extensions by William Louth Posted Jan 2, 2008 10:12 AM
  1. Back to top

    mocks vs. stubs

    Dec 31, 2007 12:39 PM by Dennis Byrne

    It should be noted that the Shale mock library is really a stub library. Not knocking Srini on this one, just pointing out this ... martinfowler.com/articles/mocksArentStubs.html . Nice article.

  2. Back to top

    JXInsight JSF AspectJ Extensions

    Jan 2, 2008 10:12 AM by William Louth

    I wanted to also point out that JXInsight also offers in addition to the trace and profile extension mentioned above a comprehensive resource metering and request/component diagnostics state capture/storage inspection facility based on our AspectJ aspect libraries.

    forums.jinspired.com/viewtopic.php?p=123#123

    forums.jinspired.com/viewtopic.php?p=109#109

    This offline inspection of request/responses as well as application/component state is extremely powerful and required for actual problem resolution if a test fails.

    William

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.