4 Replies Latest reply on Nov 13, 2013 4:22 AM by yersan

    Is arquillian the right tool to test a jsf 2.0 application on tomcat 6 that doesn't use CDI?

    yersan

      Hello all,

       

      I'm stating with arquillian due to I need to create a test suit (unit, functional and integration) for an application that runs on tomcat 6. The application doesn't use CDI for managed JSF beans, all its beans are created using @ManagedBean annotations or via declarations in faces-config file.

       

      I'm reading and knowing Arquillian. I can see that arquillian uses CDI to inject the resources in the JUnit test files, for example the @ArquillianResource annotation to test a web page using Drone. Then, it seems that I must use a container with CDI enabled to test my application that doesn't use CDI. For this reason, is Arquillian the correct tool for this environment?

       

      - If I understand well, to create my unit tests I should create the war file with the resources that I should test, for example one Managed Bean file and the clases that it requires, and inject this managed bean in the JUnit test file using CDI to allow test its methods. But in the final real environment, the bean tested will be deployed in a environment without CDI. Now, I have doubts about if these tests are the correct way to procced, because I'm testing the clases in a different environment where they are going to be deployed. The final environment will not have the weld configuration used in for example my embedded tomcat, it seems that the tomcat need some additional configurations in the web.xml to enable CDI.

       

      - For funtional and intergration tests, I should deploy my application in a tomcat with CDI enabled, since I could use drone/graphene to test the UI and I need CDI in the test files to inject @Drone and @ArquillianResource.

       

      Then, It seems that I should use an environment, in my case I should use tomcat + weld to test an application that internally doesn't use CDI to work, is this a good aproach to follow?, this configuration confused me and I don't know if I should find other tool or different environment to test my application.

       

      Thanks in advance.

        • 1. Re: Is arquillian the right tool to test a jsf 2.0 application on tomcat 6 that doesn't use CDI?
          lfryc

          Hey yersan,

           

          you don't definitely need to include CDI in order to test JSF.

           

          You can access FacesContext to retrieve your beans,

          and there could be an extension which will allow to inject @ManagedProperty (similarly to @Inject in CDI).

           

          However CDI makes in-container testing much easier thanks to type-safe dependency injection.

           

          ----

           

          The best tools you can use to test JSF is Warp for anything request/lifecycle oriented.

           

          For functional tests, you can use Drone/Graphene effectively.

           

          And then it depends on your programatic model, what else you could choose.

          1 of 1 people found this helpful
          • 2. Re: Is arquillian the right tool to test a jsf 2.0 application on tomcat 6 that doesn't use CDI?
            yersan

            Hi Lukás,

             

            Then for unit testing I should take a more deeper review to warp, definitelly it will be the way to test the JSF in both client and server sides.

             

            For functional tests, then Drone/Graphene is the correct way but to use them I must use a test server that allows CDI. Because I should inject @Drone and @ArquillianResource in my test files. It seems that this is only possible in a CDI enabled environment.

             

            For this reason, to test my application, I must deploy it in a container with a different configuration than the final productive environment, is this a correct way to test it? Maybe I have different results when the application is deployed on a server with CDI enabled (in case of tomcat I must include a new servlet in the web.xml that is not used by my application apart from other libraries in the classpath) and when it is deployed on a server that doesn't allow CDI, my final productive server, for example.

            • 3. Re: Is arquillian the right tool to test a jsf 2.0 application on tomcat 6 that doesn't use CDI?
              kpiwko

              For functional tests, then Drone/Graphene is the correct way but to use them I must use a test server that allows CDI. Because I should inject @Drone and @ArquillianResource in my test files. It seems that this is only possible in a CDI enabled environment.

              This is fortunately not true. While @Drone or @ArquillianResource follow CDI model, injection is handled by Arquillian itself and works in any environment. For instance, you can even inject @Drone when running without container.

               

              Hope that helps,

               

              Karel

              • 4. Re: Is arquillian the right tool to test a jsf 2.0 application on tomcat 6 that doesn't use CDI?
                yersan

                Hi Karel, this is a good new for me.

                 

                Yes, I have found an example in https://github.com/arquillian/arquillian-showcase that use tomcat without CDI and @ArquillianResource. I will try to use it to create an example using @Drone since I have found any sample of drone + tomcat 6 without CDI

                 

                Ok, thanks both, then it seems arquillian can be used with a tomcat 6 without CDI enabled, for unit test, use wrap, for functional/integration drone and graphene.