13 Replies Latest reply on Feb 25, 2009 11:02 AM by coenos

    SeamTest + TestNG doesn't find any TestNG annotations

    coenos

      Ok, I have this really weird problem. I have this test:


      
      public class UmbrellaTest extends SeamTest {
           QuotationBacking quotationBacking;
      
           @Test
           public void testGetProjectName() throws Exception {
      
                System.out.println("Umbrella Test  Begin");
      
                new ComponentTest() {
      
                     @Override
                     protected void testComponents() throws Exception {
                          // TODO Auto-generated method stub
                          quotationBacking = new QuotationBacking();
                          String pName = quotationBacking.getProjectName();
                          System.out.println("pName " + pName);
      
                          assert pName.equals("TRALALAL");
                     }
                }.run();
           }
      }
      
      



      And this testng.xml file


      
      <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
      <testng outputdir="test-output">
            <classpath path="D:\\xxxxx\\umbrella-ejb-0.0.1-SNAPSHOT.jar"/>
            <classpath path="D:\\xxxxx\\umbrella.war"/>
            <classpath path="D:\\xxxxx\\umbrella.ear" />
      
      <suite name="umbrella-war">
        <test verbose="2" name="xxxx.test.UmbrellaTest" annotations="JDK">
          <classes>
            <class name="xxxx.test.UmbrellaTest"/>
          </classes>
        </test>
      </suite>
      </testng>
      
      



      But when I run it, the TestNG engine doesn't recognize my test as a TestNG test. it says:


      
      [Parser] Running:
        C:\xxxxx\umbrella-war\temp-testng-customsuite.xml
      
      [RunInfo] Adding method selector: org.testng.internal.XmlMethodSelector@c68c3 priority: 10
      [TestNGClassFinder] SKIPPING CLASS class xxxx.test.UmbrellaTest no TestNG annotations found
      [SuiteRunner] Created 1 TestRunners
      [TestRunner] Running test xxxx.test.UmbrellaTest on 0  classes,  included groups:[] excluded groups:[]
      [TestRunner] Found 0 applicable methods
      
      
      



      Is there something wrong with my setup?


      Thanks for your help!
      Coen

        • 1. Re: SeamTest + TestNG doesn't find any TestNG annotations
          lcbdl888

          try right click on your testng.xml, then Run As, TestNG Suite

          • 2. Re: SeamTest + TestNG doesn't find any TestNG annotations
            coenos

            Ok I am now running the Suite with some extra classpath entries and also within a ComponentTest. I also simplified the test:


            
            public class MyTest extends SeamTest {
            
                 @Test
                 public void testThis() throws Exception{
                      
                      new ComponentTest()  {
                          @Override
                          protected void testComponents() throws Exception { 
                                 QuotationFacade facade = (QuotationFacade)Component.getInstance("quotationFacadeImpl",true);
                                assert true;           
                          }
                      }.run();
                 }
            }
            
            




            The suite now runs, but I get another Exception:


            
            
            [RunInfo] Adding method selector: org.testng.internal.XmlMethodSelector@1a33d48 priority: 10
            [TestClass] Creating TestClass for [ClassImpl uk.co.tntpost.umbrella.test.MyTest]
            [TestClass] Adding method xxxx.test.MyTest.testThis() on TestClass class xxxx.test.MyTest
            [XmlMethodSelector] Including method xxxx.test.testThis()
            [SuiteRunner] Created 1 TestRunners
            [TestRunner] Running test xxxxxx.test.MyTest on 1  classes,  included groups:[] excluded groups:[]
            [TestClass] 
            ======
            TESTCLASS: xxxx.test.MyTest
            [TestClass] Test        :          xxxx.test.MyTest.testThis()
            [TestClass] 
            ======
            
            [TestRunner] Found 1 applicable methods
            [TestRunner] WILL BE RUN IN RANDOM ORDER:
            [TestRunner]   xxxx.test.MyTest.testThis()
            [TestRunner]       on instances
            [TestRunner]      xxxx.test.MyTest@125fefa
            [TestRunner] ===
            [Invoker 23667197] Invoking xxxx.test.MyTest.testThis
            
            *********** INVOKED METHODS
            
                      xxxx.test.MyTest.testThis() 19267322
            
            ***********
            
            Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\umbrella-war\xxxxx.test.MyTest.html
            FAILED: testThis
            java.lang.NullPointerException
                 at org.jboss.seam.servlet.ServletSessionMap.get(ServletSessionMap.java:54)
                 at org.jboss.seam.contexts.BasicContext.get(BasicContext.java:49)
                 at org.jboss.seam.contexts.Contexts.lookupInStatefulContexts(Contexts.java:199)
                 at org.jboss.seam.Component.getInstance(Component.java:1939)
                 at org.jboss.seam.Component.getInstance(Component.java:1934)
                 at xxxx.test.MyTest$1.testComponents(MyTest.java:20)
                 at org.jboss.seam.mock.AbstractSeamTest$ComponentTest.run(AbstractSeamTest.java:163)
                 at xxxx.test.MyTest.testThis(MyTest.java:33)
            ... Removed 22 stack frames
            
            ===============================================
                uk.co.tntpost.umbrella.test.MyTest
                Tests run: 1, Failures: 1, Skips: 0
            ===============================================
            
            
            ===============================================
            umbrella-war
            Total tests run: 1, Failures: 1, Skips: 0
            ===============================================
            
            



            I don't understand this. Is this a bug in SeamTest ?


            Thanks for your help,
            Coen

            • 3. Re: SeamTest + TestNG doesn't find any TestNG annotations
              coenos

              Ok I looked at the Seam source code in the org.jboss.seam.servlet.ServletSessionMap.


              
               public Object get(Object key)
                 {
                    return session.getAttribute( (String) key );
                 }
              
              



              It's failing on the session.getAttribute method.


              I don't understand why there is no Session????


              Please help,
              Coen


              • 4. Re: SeamTest + TestNG doesn't find any TestNG annotations
                marcioendo.marcioendo.gmail.com

                I don't understand why there is no Session????


                I think the problem is that you're implementing your test as a ComponentTest.


                Try extending a FacesRequest and see if the results are any different.

                • 5. Re: SeamTest + TestNG doesn't find any TestNG annotations
                  coenos

                  Ok now I get another exception. I am new to testNG testing....


                  I changed the test code to:


                  
                  public class MyTest extends SeamTest {
                  
                       @Test
                       public void testThis() throws Exception{
                            /*
                            new ComponentTest()  {
                                @Override
                                protected void testComponents() throws Exception { 
                                    
                                       QuotationFacade facade = (QuotationFacade)Component.getInstance("quotationFacadeImpl",true);
                                      assert true;              
                                }
                            }.run();
                                 */
                                      
                            new FacesRequest(){
                                 @Override
                                 protected void invokeApplication() throws Exception{
                                           //QuotationFacade facade = (QuotationFacade)Component.getInstance("quotationFacadeImpl",true);
                                      assert true;
                                 }
                                
                            }.run();
                            
                       }
                  }
                  
                  



                  This is the exception:


                  
                  FAILED: testThis
                  java.lang.NullPointerException
                       at org.jboss.seam.mock.AbstractSeamTest$Request.run(AbstractSeamTest.java:492)
                       at xxxx.test.MyTest.testThis(MyTest.java:35)
                  ... Removed 22 stack frames
                  
                  



                  I do not understand this.
                  Please help,
                  Coen

                  • 6. Re: SeamTest + TestNG doesn't find any TestNG annotations
                    coenos

                    Ok, I'm back to where I started. TestNG doesn't crash anymore but I am getting the same output, whether I run a Class, a Method or a Suite. Or whether I run a FacesRequest or ComponentTest....


                    
                    Parser] Running:
                      C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\temp-testng-customsuite.xml
                    
                    [RunInfo] Adding method selector: org.testng.internal.XmlMethodSelector@1e8a1f6 priority: 10
                    [TestNGClassFinder] SKIPPING CLASS class xxxx.test.facestest.MyFacesTest no TestNG annotations found
                    [SuiteRunner] Created 1 TestRunners
                    [TestRunner] Running test xxxx.test.facestest.MyFacesTest on 0  classes,  included groups:[] excluded groups:[]
                    [TestRunner] Found 0 applicable methods
                    
                    *********** INVOKED METHODS
                    
                    
                    ***********
                    
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\umbrella-war\xxxx.test.facestest.MyFacesTest.html
                    
                    ===============================================
                        xxxx.test.facestest.MyFacesTest
                        Tests run: 0, Failures: 0, Skips: 0
                    ===============================================
                    
                    
                    ===============================================
                    umbrella-war
                    Total tests run: 0, Failures: 0, Skips: 0
                    ===============================================
                    
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\umbrella-war\toc.html
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\umbrella-war\xxxx.test.facestest.MyFacesTest.properties
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\umbrella-war\index.html
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\umbrella-war\main.html
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\umbrella-war\groups.html
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\umbrella-war\methods.html
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\umbrella-war\methods-alphabetical.html
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\umbrella-war\classes.html
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\umbrella-war\reporter-output.html
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\umbrella-war\methods-not-run.html
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\umbrella-war\testng.xml.html
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\index.html
                    Creating C:\Workspaces\EclipseTNTUmbrellaWorkspace\umbrella-parent\umbrella-war\test-output\testng-results.xml
                    
                    
                    




                    Running out of options.......


                    Thanks for any help,
                    Coen

                    • 7. Re: SeamTest + TestNG doesn't find any TestNG annotations
                      kapitanpetko

                      Wild guess: make sure you are using TestNG's annotations, and not JUnit's. Are you import-ing org.junit.Test or org.testng.annotations.Test?

                      • 8. Re: SeamTest + TestNG doesn't find any TestNG annotations
                        coenos

                        Yes, indeed, using TestNG annotations.


                        The weird thing is that when I run a clean test (from Eclipse) StartSeam is called. But when I run the test with the required embedded jboss jars, the annotations are not found (?????).


                        • 9. Re: SeamTest + TestNG doesn't find any TestNG annotations
                          coenos

                          So, I followed the instructions to get TestNG test in Eclipse plus plugin running using this setup


                          Set up TestNG and Eclipse


                          , but then I get the No annotations problem (?????).


                          Maybe a bug?

                          • 10. Re: SeamTest + TestNG doesn't find any TestNG annotations
                            marcioendo.marcioendo.gmail.com

                            How did you setup your Eclipse project?


                            I'd suggest you create a sample project following these instructions and see what you are doing differently.

                            • 11. Re: SeamTest + TestNG doesn't find any TestNG annotations
                              coenos

                              Yeah all is setup fine.


                              I have a Maven2 project and Eclipse Europa, running in Tomcat embedded Jboss.


                              I tested this also in a seam-gen project, but I get the same problem.


                              This is my test:


                              
                              @org.testng.annotations.Test
                              public class MyFacesTest extends SeamTest {
                              
                                      @org.testng.annotations.Test
                                      public void testThisNow() throws Exception {
                              
                                              new FacesRequest() {
                                                      @Override
                                                      protected void invokeApplication() throws Exception {
                                                              QuotationFacade facade = (QuotationFacade) Component
                                                                              .getInstance("quotationFacadeImpl", true);
                                                              assert true;
                                                      }
                                              }.run();
                                      }
                              }
                              
                              




                              This is my suite:


                              
                              <suite name="umbrella-war">
                                <test verbose="10" name="xxxx.facestest.MyFacesTest" annotations="JDK">
                                  <classes>
                                    <class name="xxxx.facestest.MyFacesTest">
                                    <methods>
                                        <include name="testThisNow"/>
                                      </methods>
                                      </class>
                                  </classes>
                                </test>
                              </suite>
                              
                              





                              1. bootstrap directory from the Seam distr.

                              2. hibernate-all.jar

                              3. jboss-embedded-all.jar

                              4. thirdparty-all.jar

                              5. activation.jar

                              6. jboss-seam-remoting.jar

                              7. jboss-deployers-client-spi.jar

                              8. jboss-deployers-core-spi.jar

                              9. jboss-embedded-api.jar

                              10. jboss-seam.jar

                              11. jsf-api.jar

                              12. el-api.jar



                              As far as I know this is the correct setup for integration testing Seam apps in Eclipse.


                              If you have any clue, please let me know,
                              Coen




                              • 12. Re: SeamTest + TestNG doesn't find any TestNG annotations
                                marcioendo.marcioendo.gmail.com

                                With Seam 2.1.0.GA, seam-gen project, I get tests running with no problems.


                                Your jars seems different though. Make sure you follow the readme.txt in the seam-gen project:


                                If you want to run tests using the Eclipse TestNG plugin, you'll need to add
                                these jars to the top of your TestNG classpath.  Using the Run Dialog, select
                                xml suite to run, and add /lib/test/jboss-embedded-all.jar, 
                                /lib/test/hibernate-all.jar, /lib/test/thirdparty-all.jar, /lib/jboss-embedded-api.jar, 
                                /lib/jboss-deployers-client-spi.jar, /lib/jboss-deployers-core-spi.jar,  and 
                                /bootstrap as the first entries in the User classpath.


                                • 13. Re: SeamTest + TestNG doesn't find any TestNG annotations
                                  coenos

                                  Ok, I am running a Mavenized project.


                                  The other jar's I need to add, otherwise the container won't start. I need Seam in the classpath. The other jar's are needed otherwise Seam won't start :)