-
1. Re: Right way to write JSFUnit tests
ssilvert Aug 16, 2009 9:03 PM (in response to guima)Hi Eduardo,
It's probably not appropriate to add messages to the FacesContext at that point. Inside the test, you are looking at the FacesContext as it exists at the end of the request. Since the request is over, and the JSF lifecycle is over, a new FacesMessage added to the FacesContext is in an undefined state.
You could install a PhaseListener for test purposes that adds a FacesMessage at the desired time during the JSF lifecycle. Then do assertions against the message in your test.
I've considered adding a feature that actually gives your test a callback during the lifecycle for just this kind of thing. But until your post, I haven't seen any demand for such a feature.
The usual way people test FacesMessages today is to just let the test go through the user interface and let the FacesMessage get created naturally. Then you do assertions to make sure that the FacesMessage was added as expected.
Stan -
2. Re: Right way to write JSFUnit tests
guima Aug 19, 2009 7:52 AM (in response to guima)Hi Stan,
Thank you for your response. You told me exactly what was happening and explained some alternatives. It made me see the importance of a good understanding of JSF lifecycle.
I wrote tests just letting FacesMessages get created naturally. It was very easy and quick to create tests getting FacesMessages and doing the assertions. JSFUnit is excellent.
Eduardo