Some developers find the need to pass parameters to the test environment. Since JSFUnit is running "in-container", this can be a bit of a challenge.
With JSFUnit running on top of Cactus, the suggestions in the Cactus FAQ also apply to JSFUnit. See "How do I parametrize my cactus tests?"
So Cactus suggests two options:
- Use system properties
- Add the properties to cactus.properties. cactus.properties needs to be on the classpath of the container and each property will be exported to a system property.
The JSFUnit API provides a third option. That is, JSFUnit allows you to access any request parameters that were passed to the redirector. The simplest way is to pass these parameters to the ServletTestRunner when you are running JSFUnit tests from a browser:
Then, you can access the param from any JSFUnit test:
JSFSession jsfSession = new JSFSession("/index.jsf"); Map<String, String> params = jsfSession.getRedirectorParams(); String myparamValue = params.get("myparam");
Note that JSFSession.getRedirectorParams() returns a Map<String, String> and not Map<String, String>. This is because it is giving you the value of ServletRequest.getParameterMap().
If you are not using the browser to run your tests, passing parameters to Cactus' redirector is a little more difficult. You will need to use the Cactus API to make sure that calls to the redirector include your params. If you need help with this, post to the JSFUnit Forum.