Version 3

    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?"
    http://jakarta.apache.org/cactus/faq.html#faq_parametrize

     

    Also see http://jakarta.apache.org/cactus/integration/manual/howto_config.html.

     

    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:

    http://localhost:8080/myjsfapp/ServletTestRunner?suite=com.foo.JSFUnitTest&xsl=cactus-report.xsl&myparam=foo
    

     

    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")[0];

    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.