8 Replies Latest reply on Jul 22, 2009 11:24 PM by David Bolton

    Running JSFUnit tests inside Eclipse

    Greg Cook Newbie

      I am working on a project with the following technologies:
      - JSF 1.2
      - RichFaces 3.3
      - GlassFish v2
      - Eclipe 3.4

      We are trying to implement JSFUnit for our web pages. We would like to run these JSFUnit tests inside Eclipse. I know we can run these tests with a Web browser (http://www.jboss.org/jsfunit/gettingstarted.html).

      1) But can we execute these tests using the JUnit plugin for Eclipse?
      2) Do we have to use the Cactus plugin for the JSFUnit tests?

        • 1. Re: Running JSFUnit tests inside Eclipse
          Stan Silvert Master

          I'm not an Eclipse user myself, but I know that many people have gotten JSFUnit to run with it. Perhaps one of those users will provide some tips. I also suggest you search this forum for Eclipse.

          You can run JSFUnit tests in any way that you normally execute JUnit. I have instructions for running JSFUnit from Maven or Ant at the bottom of this page:
          http://www.jboss.org/community/docs/DOC-10967

          Since test execution is based on Cactus, the Cactus plugin might be a good option. However, I'm not familiar with it so I can't say for sure. The Cactus web site should be a good source of information as well.

          Regards,

          Stan

          • 2. Re: Running JSFUnit tests inside Eclipse
            Greg Cook Newbie

            Thank you Stan for your reply.

            When I am runnign the tests with Web browser, the test results are different everytime. I assume the browser is caching the web page which is affecting my test results. Is there a problem with the JSF component tree?

            The problem is I am getting null pointers with the server.getCurrentViewID(). Have you ever seen this happening?

            java.lang.NullPointerException
             at org.jboss.jsfunit.jsfsession.JSFServerSession.getCurrentViewID(JSFServerSession.java:76)
             at com.taske.tests.root.ReportsPageTests.testInitialPage(ReportsPageTests.java:36)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at junit.framework.TestCase.runTest(TestCase.java:154)
             at junit.framework.TestCase.runBare(TestCase.java:127)
             at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
             at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
             at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
             at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:224)
             at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
             at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101)
             at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224)
             at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
             at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doPost(JSFUnitServletRedirector.java:46)
             at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
             at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224)
             at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
             at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doGet(JSFUnitServletRedirector.java:52)
             at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
             at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
             at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
             at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:116)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
             at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
             at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
             at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
             at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
             at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
             at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
             at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
             at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
             at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
             at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
             at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
             at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
             at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
             at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
             at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
             at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
             at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
             at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
             at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
             at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
             at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
             at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
             at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
             at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
             at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
             at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)


            • 3. Re: Running JSFUnit tests inside Eclipse
              Greg Cook Newbie

              More info.

              I am using Facelets with my JSF pages. The problem is with the pages using the Facelets templates.

              The second ServletTestCase in the suite will fail. Reverse, the order and the second fails while simulating clicks on the top level menu items.

              Any ideas?

              • 4. Re: Running JSFUnit tests inside Eclipse
                Stan Silvert Master

                Hi Greg,

                Can you post your new question to a new topic?

                Thanks,

                Stan

                • 5. Re: Running JSFUnit tests inside Eclipse
                  Stan Silvert Master

                  Also, please post your test source.

                  Stan

                  • 6. Re: Running JSFUnit tests inside Eclipse
                    Tim Evers Master

                    I use Eclipse and have been successfully running my JSFUnit tests from within Eclipse since I started using JSFUnit a fair while ago.

                    Essentially you can run them like any other JUnit test after you have a VM argument. I have done this a way which I will describe but this is by no means the only way to do it. I have set the JVM Arg in the Default JVM Arguments line that my project executes on.

                    So to see this, in Eclipse go to:
                    Window -> Preferences -> Java -> Installed JREs -> select your JVM that you use -> Edit

                    Now, in the Default VM Arguments line you will need to put this:
                    -Dcactus.contextURL={protocol}://{host}:{port}/{app-context-url}

                    So for example this is mine:
                    -Dcactus.contextURL=http://localhost:8080/gekko-tje

                    After you have done this you should be able to go to any of your JSFUnit tests and do a Run As -> JUnit test and it should just work.
                    This assumes that your classpath is set up correctly and you have deployed your application correctly.

                    If you have any more problems just post them here and I'll try to answer it all.

                    Stan should I do a wiki page on this?

                    • 7. Re: Running JSFUnit tests inside Eclipse
                      Stan Silvert Master

                       

                      "Kragoth" wrote:

                      Stan should I do a wiki page on this?

                      Yes! Thanks for offering. I put a placeholder for you at http://www.jboss.org/community/docs/DOC-13427. You can just edit that if you want.

                      It is already linked to the main docs page.

                      Stan

                      • 8. Re: Running JSFUnit tests inside Eclipse
                        David Bolton Newbie

                         

                        "Kragoth" wrote:

                        After you have done this you should be able to go to any of your JSFUnit tests and do a Run As -> JUnit test and it should just work.
                        This assumes that your classpath is set up correctly and you have deployed your application correctly.


                        The process sounds simple enough, but the bigger question for me is how to best setup the projects to make testing a quick and easy task.

                        For instance, I have run JSFUnit tests via the browser and Maven. The quickest way for me to do both of these is to let Maven do the packaging, and then either let Maven continue to run the tests, or deploy the package to the server and run in the browser. Not necessarily a quick process, but if we run as part of the build it doesn't need to be lightning quick either.

                        When we are developing in Eclipse, however, we want as quick a process as possible. In that case, I want something that allows me to have two separate projects (as per the Maven instructions), in order to keep the additional configuration separate, but where the deployment is kept up to date as I develop, so that all I need to do is run the JSFUnit test. (For the record, we are using Eclipse's Web Tools Project and Tomcat)

                        Any ideas on how to achieve this? To me, this is the tricky part -- how to maintain developer productivity and not impinge on their workflow.

                        We're not using JSFUnit fully yet, more investigating how it will work for us, so I apologise if this question is simplistic or missing the point.