1 Reply Latest reply on Feb 18, 2009 4:30 PM by Stan Silvert

    Deploying the JSFUnit Test Cases on a Remote Server

    Manish Jain Newbie

      Hi Stan,

      Thanks for your help in my earlier post. I have one more requirement and I need to know how I can get that working.

      I have written JSFUnit Test class for 10 different views of my application. When I deploy the application and the test classes on the same server it works. Now, what I want to do is deploy all the JSFUnit Test classes on a remote server and use it from there to test the view which is generated from the application running on my PC or any other PC. The server is like a repository for all test cases and who so ever want to check that his modifications doesn't break the application calls the JSFunit test- cases that are deployed on the server machine.

      In general, we call the JSFUnit test classes using this URL format:-

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


      As per my requirement, I added one more parameter to this URL called "target-url", which specifies the details of the machine where the application is hosted.

      So, the url format changes to:-

      http://localhost:8080/AppName/ServletTestRunner?suite=com.foo.JSFUnitTest&xsl=cactus-report.xsl&target-url=http://machine22:8082/AppName


      Now, after I did that I expected to get the parameter in my test-class in this manner:-
      this.request.getParameter("target-url");

      But, to my surprise this parameter was not all there. After that i tried a lot of things to get it but I was not able to retrive it in my test-class.

      So, I had to develop a small API to forward the request to the test-class, while giving me the value of the parameter "target-url".

      Now, I have the url(target-url) of the application(deployed on some other machine) in my test-class. So, I tried to get the org.jboss.jsfunit.jsfsession.JSFSession in this manner:-

      ParameterDetails paramDetails = ParameterDetails.getInstance(); //Singleton Class
      
       String targetURL = paramDetails.getTargetURL(); // = http://machine22:8082/AppName
      
       JSFSession jsfSession = new JSFSession(targetURL + "/login.html");


      I expected to get a JSFSession, but that doesn't happen. It tries to look for the application on my machine

      So, JSFUnit throws an exception where the most interesting thing for me to watch was the details of the URL........The URL for which it was trying to execute the test looks like this

      http://localhost:8080/AppNamehttp://machine22:8082/AppName


      Please tell me, how can I obtain the JSFSession of the application running on some other machine?

      Manish








        • 1. Re: Deploying the JSFUnit Test Cases on a Remote Server
          Stan Silvert Master

          There is no way to get a reference to JSFSession on another machine. JSFSession is not a remote object. Tests execute in the same context as the WAR, which has tremendous advantages because you don't need mock objects and you get an extremely reliable test environment.

          First, take a look at this wiki: http://www.jboss.org/community/docs/DOC-10971
          It describes the requests that happen in a JSFUnit test. The test request kicks off your tests. The tests kick of JSF requests. The artifacts available to you are those created from the JSF requests.

          It is possible to get your extra url param using a filter, but I think you are going down the wrong road and should probably ditch that idea altogether.

          The best way to set things up is to kick off your tests from Maven or Ant. Using the ServletTestRunner as you are doing is fine for running tests interactively from a browser, but for a more permanent solution you should run them from your build. From a logical point of view, you can run JSUnit tests the same way you would run any other JUnit test. See the bottom of this page for articles on setting this up with Maven or Ant: http://www.jboss.org/community/docs/DOC-10967

          JSFUnit is an in-container testing framework. So one way or another, the server's classloader has to be able to load your tests. The easiest way to achieve this is to bundle the test classes in WEB-INF/classes. However, if you are using JBoss AS 5, it is easier to use the JSFUnitDeployer, which can load your test classes from any URL or even from multiple locations. See http://www.jboss.org/community/docs/DOC-10975

          My suggestion is to check in your tests as part of the build just as you would any other JUnit test. Then each developer can build the "JSFUnified" WAR to use for testing on a local machine. I don't understand the advantage of loading tests on a remote box.

          Stan