myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aleksei Valikov <>
Subject Re: Unit testing backing beans / custom components in JSF
Date Wed, 24 May 2006 09:30:25 GMT

> How to unit test JSF code? Which test framework should be used for
> custom component/ backing beans unit testing?
> I am curious how do MyFaces developers (not users) test the various
> components in MyFaces/Tomahawk releases?

Backing beans are easy to test since they generally follow the IOC pattern. Just 
instantiate the bean and inject whatever services/beans it need via setters. We 
use Spring, so we often simply autowire backing beans properties.
Testing scenarious for backing beans are quite simple:
1. Initialize the bean (and appropriate dependent beans).
2. Set properties.
3. Execute the action.
4. Check action outcome.
5. Check aposteriour values of properties.

As for the components, it's a bit more complex. From my point of view there's 
two things you can/have to test: (a) if the component renders itself as you want 
it to be rendered and (b) if what you want to be rendered actually works.

Testing (a) is not a big problem. Instantiate a component, provide mock/dummy 
ResponseWriter, render the component and simply check if the rendered HTML (or 
whatever) is allright. In some of my components I use testing framework from 
Shale, it provides a couple of useful tools.

Testing (b) is much more complex. Okay, from my component I can generate a pile 
of HTML/Javascript/CSS, but I need to make sure that alltogether this builds, 
for instance, a working DHTML menu which functions on different browsers. I see 
no other possibility as manual testing here.


View raw message