You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by arti <ar...@tambas.at> on 2006/05/24 10:41:37 UTC

Unit testing backing beans / custom components in JSF

Hello,

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? 

Thanks,
Arti


Re: Unit testing backing beans / custom components in JSF

Posted by Aleksei Valikov <va...@gmx.net>.
Hi.

> 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.

Bye.
/lexi

Re: Unit testing backing beans / custom components in JSF

Posted by "Mirek B." <wi...@gmail.com>.
Hi Arti,

You will be interested in 
http://struts.apache.org/struts-shale/features-test-framework.html

-- mirek

arti wrote:
> Hello,
> 
> 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? 
> 
> Thanks,
> Arti
> 
>