6 Replies Latest reply on Nov 4, 2009 5:44 PM by Pete Muir

    Unit tests

    Hernan Moreno Newbie

      I'm starting a new project and my choice is Weld. Currently I know it is CR1 and I think is stable enough to use it seriously(Right?). Since there is no updated documentation(yet) I was checking the examples from the distribution. They are nice but I did not see any test... now my question.


      are you guys planning to provide a tool testNG based? in order to do these unit tests? I saw somewhere in the forum something about it, but I don't know the current status of that. A complete example (hopefully all) with their respective unit tests will be really great. Specially those showing not only the DI tests stuff, but integration tests with ejb standalone(specially).


      That will help a lot more to people to understand better the features of Weld.


      By the way, congratulations for all the effort and thank you for pushing Java EE beyond its limits.



        • 1. Re: Unit tests
          Gavin King Master

          I'm starting a new project and my choice is Weld.

          Cool :-)



          Currently I know it is CR1 and I think is stable enough to use it seriously(Right?).

          The CR1 is appropriate for use in development. Of course, there are a few bugs, some of which we already know about. In a few weeks will will deliver a release that is suitable for use in production.



          Since there is no updated documentation(yet) I was checking the examples from the distribution. They are nice but I did not see any test... now my question.

          Hrm, we have a test harness for the TCK, but that may be a bit over-engineered for general development testing. I guess this is something I need to chat with Pete about.

          • 2. Re: Unit tests
            Hernan Moreno Newbie

            Great, this is something cool.

            • 3. Re: Unit tests
              Steven Boscarine Apprentice

              I am very interested in this as well.  If you need any help, such as an alpha/beta tester, please let me know. 


              • 4. Re: Unit tests
                Pete Muir Master

                IMO we need to over a number of testing options ranging from simple scaffolding (e.g. a quick unit test for prototyping) through to full integration testing.


                Aslak is currently working on building out the testing framework we want to use for Seam 3. What we are planning is a framework which allows you to write a test once, and run in multiple places (e.g. standalone Weld container, in Embedded JBoss, in full JBoss AS, in GlassFish, in Tomcat, in Jetty, in a SeamTest esque mock-JSF environment etc.), using either TestNG or JUnit, from either the command line or your IDE. This is being built on the same foundations as the new Embedded JBoss, so should work great in combo :-)


                Of course, you will be able to specify that test is only for integration testing etc. You'll also be able to easily configure what deployment descriptors (beans.xml etc.) to put into the deployment, and eventually configure the deployment descriptor from the test using a fluent API.


                I hope we will have an alpha of this by mid-November.

                • 5. Re: Unit tests
                  Steven Boscarine Apprentice

                  Pete mentioned a sophisticated test framework for Weld. 


                  Are there examples of less sophisticated tests that we can use for testing basic dependency injection and code functionality? 


                  At the very least, do any examples show how to instantiate the container via TestNG or JUnit?


                  For example, if we wanted to modify the numberguess org.jboss.weld.examples.numberguess.Generator class, and change the line:


                   //  private int maxNumber = 100;
                     private int maxNumber = 100000;
                  



                  and then write a test to confirm that it now is producing random numbers from above 100, how would we do so?  Would that require a full, sophisticated suite?



                  Thanks,
                  Steven

                  • 6. Re: Unit tests
                    Pete Muir Master

                    No. For now you can use then TestContainer class from org.jboss.weld:weld-core-tests and do


                    TestContainer container = new TestContainer(new MockServletLifecycle(), Generator.class);
                    container.startContainer().ensureRequestActive();
                    
                    // Test
                    
                    container.stopContainer();