10 Replies Latest reply on Sep 14, 2009 10:25 PM by pksiv

    SeamTest + JUnit

    blabno

      Hello !
      I'm a Netbeans addict and will not switch to Eclipse, but since there is no TestNG support for Netbeans I'd like to run SeamTest's with JUnit. I wrote JUnit4 test extending SeamTest but there is lots of initialization problems. I guess that is no JUnit issue but some my fault.


      Can you tell me how testing with SeamTest works ?


      My project structure :


      Ear+
         |-ejb.jar
         |-web.war



      Since tests are in ejb.jar Netbeans puts in classpath the ejb build directory, which gets scanned, and since there is no components.xml I get :

      java.lang.IllegalArgumentException: You must specify
      org.jboss.seam.core.init.jndiPattern or use @JndiName


      As I understand application is not deployed on server. How then all the EJB's get injected ? I'm having some jndi problems with that.
      I also get lots of ClassNotFoundExceptions. As far as I understand,  init() method in SeamTest scans all jars in test class path so I put entire EAR there, but this seems to be silly solution.


      Tell me then what shall I put in test classpath ?
      How should my jndiPattern look like, same as for AS JBoss ?


      I have jboss-seam-2.0.1.CR1 and jboss-4.2.3.GA

        • 1. Re: SeamTest + JUnit
          pmuir

          This sounds more like a problem with your classpath than with using JUnit. You need to use a directory structure ala seam-gen.


          I documented how to use JUnit rather than TestNG in trunk (you need to run trunk too as I refactored SeamTest to allow this)

          • 2. Re: SeamTest + JUnit
            blabno

            Thanks for reply Pete. Indeed it was classpath. I do not understand third sentence. What do you mean in trunk? In svn trunk? If so then where exactly. I've looked at


            http://anonsvn.jboss.org/repos/seam/trunk/doc/Seam_Reference_Guide/en-US/Testing.xml



            and found nothing on JUnit.


            I've managed to lunch JUnit4 test in NetBeans6.1 for jboss-seam-2.0.1.CR1. I have some minor problem like messages do not get injected or values not loaded from messages.properties. But test gets executed. I will document my work this week. I've managed with NetBeans directory structure.




            • 3. Re: SeamTest + JUnit
              blabno

              My mistake. Found changes and docs in 2.1.0.A1.


              Problem with JUnit4 is that @BeforeClass method must be public static and AbstractSeamTest.setupClass() is not static. Should I call it from constructor ?
              Other thing is that if I have several test classes, would JBossEmbedded start several, am I right ? Can't this be optimized somehow ?

              • 4. Re: SeamTest + JUnit
                pmuir

                Read the javadoc, it tells you when to run the setup and cleanup methods (before/after each instance). startSeam() and stopSeam() cause embedded to boot/stop - so run them once per suite.

                • 5. Re: SeamTest + JUnit
                  blabno

                  I've read javadoc Pete ! I know what those methods do.
                  But in JUnit method that needs to be run once per class must be static, and both setupClass() and startSeam() are not static, so I must call them from some else place. Constructor seems to me the only choice and I was curious if you see any cons.
                  By the way, when you say suite, do you mean single class ?


                  Although, when you answer me I often have a feeling of getting reprimand, Than You for valuable attention.

                  • 6. Re: SeamTest + JUnit
                    pmuir

                    JUnit still seems to be lacking in this regard (no way to run a method just after an instance is instantiated, just before it is destroyed, no way to run a method before running a suite, after running a suite). A suite is multiple classes.


                    Complain to them, not us ;-)


                    I can make the start/stop Seam methods static but not the setup/cleanup Class. File a feature request in JIRA.

                    • 7. Re: SeamTest + JUnit
                      blabno

                      Finally I've managed to integrate SeamTest with JUnit on NetBeans and wrote tutorial on that.
                      You can read it here : seamtest4junit.bernard.labno.pl.

                      • 8. Re: SeamTest + JUnit

                        Pete Muir wrote on Jul 27, 2008 19:18:


                        I documented how to use JUnit rather than TestNG in trunk (you need to run trunk too as I refactored SeamTest to allow this)


                        Sounds nice. Since I'm trying to write JUnit tests for my application this doc would be very helpful. But I'm not the best in finding things, so could you please tell me where to find this doc?


                        Thanks in advance
                        Newlukai

                        • 9. Re: SeamTest + JUnit
                          sjmenden

                          Can you add that link and a short description in our knowledge base? http://www.seamframework.org/Documentation/KnowledgeBase

                          • 10. Re: SeamTest + JUnit
                            pksiv

                            Bernard Labno wrote on Aug 14, 2008 08:48:


                            Finally I've managed to integrate SeamTest with JUnit on NetBeans and wrote tutorial on that.
                            You can read it here : seamtest4junit.bernard.labno.pl.


                            This link doesn't appear to be work anymore. Any help running SeamTest with JUnit ?