InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

JSF Testing Tools

Posted by Srini Penchikala on Dec 31, 2007

Sections
Architecture & Design,
Development,
Operations & Infrastructure
Topics
Artifacts & Tools ,
Open Source ,
Unit Testing ,
Java
Tags
Testing ,
Frameworks ,
JSFUnit ,
Shale Test

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.

Srini Penchikala currently works as Security Architect and has 17 yrs of experience in software product management.

mocks vs. stubs by Dennis Byrne Posted
JXInsight JSF AspectJ Extensions by William Louth Posted
  1. Back to top

    mocks vs. stubs

    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

    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

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.

Beauty Is in the Eye of the Beholder

Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.

Architecting Visa for Massive Scale and Continuous Innovation

John Davies examines Visa’s architecture and shows how enterprises have architected complex integrations incorporating Hadoop, memcached, Ruby on Rails, and others to deliver innovative solutions.

Max Protect: Scalability and Caching at ESPN.com

Sean Comerford unveils ESPN.com’s architecture, what components are used and why, and the current changes the website goes through.

The Seven Deadly Sins of Enterprise Agile Adoption

Are there repeated patterns of failure on Enterprise Agile Enablement efforts? Sanjiv and Arlen discuss Seven Deadly Sins to avoid when adopting Agile in an enterprise.

Questions for an Enterprise Architect

Erik Dörnenburg answers: What is Enterprise and Evolutionary Architecture?, discussing 4 issues: Turning strategy into execution, Ensuring conformance, Where do the architects sit? Buying or building?

Wrap Your SQL Head Around Riak MapReduce

Sean Cribbs explains what Map-Reduce and Riak are, why and how to use Map-Reduce with Riak, and how to convert SQL queries into their Map-Reduce equivalents.