5 Replies Latest reply on Dec 27, 2010 1:02 PM by ssilvert

    How do I use JSFUnit in these circumstances?

    jimd11

      Hi all,

       

      I'm trying to use JSFUnit without success, and would really like to get it working as it would provide a new layer of testing for me.

       

      Let me describe what I'm doing:

       

      I have a JBoss Seam 2.1 application, built using JBoss Tools in Eclipse. It has a Web project, an EJB project (where all the logic is) and is deployed as an EAR. It runs on JBoss 5. The JSFs use Richfaces.

       

      I'd *like* to use JSFUnit to test this by running the tests within Eclipse, deploying the application on the server within Eclipse itself. Even better would be using with within the embedded JBoss that SeamTest runs inside, but I've not found any documentation that leads me to believe this can be done.

       

      I don't want to have to amend my WAR file, either by adding new JARs or by amending the web.xml, so I was looking at the ASMicrodeployer for JSFUnit. I can get this to deploy (getting the success message on JBoss startup), but I'm getting a lot of errors around the servlets required.

       

      I also tried by using the Ant tasks, operating on the exploded WAR within the EAR on the JBoss deployed inside Eclipse. It constantly gives me errors stating that it cannot find classes, even though I know the relevant JARs are on the classpath as I've ECHOed them. I think this would be the most promising way of running the tests.

       

      My question is - could anyone offer advice on how to execute these tests in the manner I described above?

       

      Thanks in advance

       

      Jim

        • 1. Re: How do I use JSFUnit in these circumstances?
          ssilvert

          There are three approaches to this.

           

          1. Create a "testable" version of your WAR that gets bundled instead of the production version.  This testable version contains a modified web.xml and the extra jars.  It just requires some build tricks to make sure the testable WAR is the one that gets bundled with your EAR.  That's pretty easy to do in Maven but tougher in Ant.
          2. Use the JSFUnit Deployer.  I was going back and looking at this yesterday and I have reason to believe that the JSFUnit 1.3 version of the deployer was not built properly.  I don't know if I will have time to go back and investigate this further.  You might want to try the JSFUnit 1.2 version.  The other thing about the deployer is that it only works with JBoss AS5.  A lot of things changed in the deployment architecture in AS6 and it changes even more in AS7.  So we will deprecate the JSFUnit Deployer anyway.
          3. Use Arquillian.  This is the new way to do things going forward and it will be much smoother and easier.  You can start using Arquillian-based JSFUnit tests right away if you are using a Servlet 3.0 container.  JSFUnit 2.0 will support older containers.  See the last section of the Arquillian documentation and this page on JSFUnit with CDI.

           

          Regards,

           

          Stan

          1 of 1 people found this helpful
          • 2. Re: How do I use JSFUnit in these circumstances?
            jimd11

            Thanks Stan, I'll investigate the options you offer.

             

            I like the look of Arquillian, so will probably look at that approach first.

            • 3. Re: How do I use JSFUnit in these circumstances?
              ssilvert

              Jim Gallagher wrote:

               

              Thanks Stan, I'll investigate the options you offer.

               

              I like the look of Arquillian, so will probably look at that approach first.

              Great.  Just make sure you are using a Servlet 3.0 container like JBoss AS6.  The version that works on older containers probably won't be ready for awhile.

               

              Stan

              • 4. Re: How do I use JSFUnit in these circumstances?
                jimd11

                OK, to update on this.

                 

                I decided against using Arquillian, for a couple of reasons:

                 

                • I'm not familiar with Maven, and have no real need to learn at the moment
                • The need for JBoss AS6 is a show-stopper, as I'm limited to AS5 in production and need to develop on the same stack as in prod

                 

                I appreciate that #1 above is not a valid excuse, and that I really should learn about it, but it's not a priority at the moment.

                 

                So I went back to JSFUnit 1.2 microdeployer, and simply could not get this to work. I wanted it to recognise my WAR without me renaming it, so I amended the parameter in the exploded deployer, but no joy. This may be because my WAR was deployed as part of an EAR.

                 

                So I returned to Ant, and finally achieved success by doing the following:

                 

                • I deploy my EAR to the JBoss server within Eclipse (this is stored in a plugin directory under the workspace)
                • I run an Ant script which JSFUnit-ifies the WAR file, deletes the original WAR and renames the new one to the old name. This step also copies the tests to the WEB-INF/classes directory in the WAR
                • I then start the server within Eclipse
                • I run JSFUnit tests using a JUnit run configuration with the cactus VM arg set, and these execute appropriately

                 

                The main and ugly drawback is that a change to my tests requires a full rebuild and redeploy.

                 

                I'm fully aware that this a less than sub-optimal solution, but after nearly 2 weeks of wrestling with this I'm at least happy to have the ability to execute JSFunit tests. Now I have to learn how to use JSFUnit effectively!

                 

                If anyone has any suggestions on how to improve this approach, I'll gladly listen, but at the moment it works, if clunkily.

                • 5. Re: How do I use JSFUnit in these circumstances?
                  ssilvert

                  I wish I had time to work on the deployer.  It's the best way to do things on AS5.0, but it looks like it's not working on AS5.1.  Like I said before, it would need to be completely rewritten if we were to use it with AS6. Since we are moving toward Arquillian it's hard to justify putting in the time and effort to get this Cactus-based solution udated.

                   

                  Stan