Hi, Backing beans, I think, are slightly more than POJOs, since those are JSF aware beans - which use JSf objects like FacesContext, Application, VariableResolver etc. Unit testing these outside container, will require stubs for such objects. Shale provides mock objects, but it has dependency on Struts and Shale core, which we donot want.
Our application is pure MyFaces application. I am looking for a JSF test framework for MyFaces only. Same is true for testing custom component as well, since the components and renderers also use FacesContext - e.g. save and restore state methods / encode decode methods. Regards, Arti -----Original Message----- From: Aleksei Valikov [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 24, 2006 11:30 AM To: MyFaces Discussion Subject: Re: Unit testing backing beans / custom components in JSF 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

