8 Replies Latest reply on Sep 10, 2008 8:03 AM by Daniel Hinojosa

    Testing SEAM Application with TestNG

    Vishnu Kommini Newbie

      Hi,


      I am trying to write testcases using TestNG for an application developed using SEAM and JSF.


      we (as Front End team) generate XML request and passes to Middleware via Web Service call. Middleware will perform some validations and talk to dataabse and other third party tools to complete the process. so All we need to do is generate similar xml request using TestNG. for your info, Application is currently working fine using JBoss Seam in production.


      1. My first question is, do we need JBoss Server (I mean local server , or embeddedone)
      2. I am not using any jboss server, I am not getting any error, while running tests and it doesn't run any methods in the test class.any suugestion, what is causing the issue.


      Thank you,
      VK

        • 1. Re: Testing SEAM Application with TestNG
          Daniel Hinojosa Master

          1. Depends on the level of testing, for integration testing that seems like it would work.
          2. Without code it is harder to help.

          • 2. Re: Testing SEAM Application with TestNG
            Vishnu Kommini Newbie
            Thank you Daniel. Here with I am sending code for the following files.

            1. LoginTest.java
            2. testing.xml
            3. Ant Build.xml

            1. LoginTest.java

            package com.test;

            //import com.beust.testng.annotations.*;
            import org.apache.commons.lang.*;
            import org.jboss.seam.mock.BaseSeamTest.ComponentTest;

            import org.jboss.seam.mock.SeamTest;
            import static org.jboss.seam.ScopeType.CONVERSATION;

            import org.jboss.seam.core.Manager;
            import org.jboss.seam.web.Session;
            import org.jboss.seam.mock.SeamTest;
            import org.testng.annotations.Test;


            /**
            * Tests StringUtils
            */
            public class LoginTest extends SeamTest
            {
                   
                    @Test
                    public void isEmpty()
                    {
                            System.out.println("-- isEmpty ---");
                            assert StringUtils.isBlank(null);
                            assert StringUtils.isBlank("");
                    }

                    @Test
                    public void trim()
                    {
                            System.out.println("-- trim ---");
                            assert "foo".equals(StringUtils.trim("  foo   "));
                    }
                           
                    @Test
                    public void testSearch() throws Exception
                    {
                            new FacesRequest()
                            {
                                    @Override
                            protected void updateModelValues() throws Exception
                            {
                                            setValue("#{identity.username}", "site2test");
                                setValue("#{identity.password}", "test2day");
                            }
                       
                            @Override
                            protected void invokeApplication()
                            {
                                    assert invokeMethod("#{identity.login}").equals("success");
                            }
                            }.run();
                    }
                   
                @Test
                public void testLogin() throws Exception
                {
                    System.out.println("-- testLogin 1 ---");
                     new ComponentTest()
                     {
                            
                        @Override
                        public void testComponents() throws Exception
                        {
                            System.out.println("-- testLogin 2 ---");
                            //assert getValue("#{identity.loggedIn}").equals(false);
                            System.out.println("-- testLogin 3 ---");
                            setValue("#{identity.username}", "site2test");
                            System.out.println("-- testLogin 4 ---");
                            setValue("#{identity.password}", "test2day");
                            setValue("#{identity.destination}", "BALANCES");
                            invokeMethod("#{identity.login}");
                           
                            assert getValue("#{user.firstName}").equals("site2test");
                        }
                    }.run();    
                }
            }

            -------------------------------------------------------


            • 3. Re: Testing SEAM Application with TestNG
              Vishnu Kommini Newbie
              Thank you Daniel. Here with I am sending code for the following files.

              1. LoginTest.java
              2. testing.xml
              3. Ant Build.xml

              1. LoginTest.java

              package com.test;

              //import com.beust.testng.annotations.*;
              import org.apache.commons.lang.*;
              import org.jboss.seam.mock.BaseSeamTest.ComponentTest;

              import org.jboss.seam.mock.SeamTest;
              import static org.jboss.seam.ScopeType.CONVERSATION;

              import org.jboss.seam.core.Manager;
              import org.jboss.seam.web.Session;
              import org.jboss.seam.mock.SeamTest;
              import org.testng.annotations.Test;


              /**
              * Tests StringUtils
              */
              public class LoginTest extends SeamTest
              {
                               @Test
                      public void isEmpty()
                      {
                              System.out.println("-- isEmpty ---");
                              assert StringUtils.isBlank(null);
                              assert StringUtils.isBlank("");
                      }

                      @Test
                      public void trim()
                      {
                              System.out.println("-- trim ---");
                              assert "foo".equals(StringUtils.trim(" foo "));
                      }
                                       @Test
                      public void testSearch() throws Exception
                      {
                              new FacesRequest()
                              {
                                      @Override
                              protected void updateModelValues() throws Exception
                              {
                                              setValue("#{identity.username}", "site2test");
                                  setValue("#{identity.password}", "test2day");
                              }
                                           @Override
                              protected void invokeApplication()
                              {
                                      assert invokeMethod("#{identity.login}").equals("success");
                              }
                              }.run();
                      }
                           @Test
                  public void testLogin() throws Exception
                  {
                      System.out.println("-- testLogin 1 ---");
                       new ComponentTest()
                       {
                                            @Override
                          public void testComponents() throws Exception
                          {
                              System.out.println("-- testLogin 2 ---");
                              //assert getValue("#{identity.loggedIn}").equals(false);
                              System.out.println("-- testLogin 3 ---");
                              setValue("#{identity.username}", "site2test");
                              System.out.println("-- testLogin 4 ---");
                              setValue("#{identity.password}", "test2day");
                              setValue("#{identity.destination}", "BALANCES");
                              invokeMethod("#{identity.login}");
                                               assert getValue("#{user.firstName}").equals("site2test");
                          }
                      }.run();
                  }
              }

              -------------------------------------------------------

              2. testing.xml

              <!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >

              <suite name="Test Suite">

                <test name="TestNG Basic Tests">

                  <classes>
                               <class name="com.test.LoginTest" />
                  </classes>

                </test>

              </suite>

              ------------------------------------------------------------


              3. Ant Build.xml

              <project name="TestNG BAISI Application" default="test" basedir=".">

                   <property name="src.dir" value="src" />
                   <property name="test-output.dir" value="test-output" />

                        
                   <!-- Set Classpath -->
                  <fileset id="lib" dir="./lib">
                      <include name="*.jar" />
                  </fileset>
                 
                  <path id="build.classpath">
                      <fileset refid="lib" />
                  </path>
                   

                   <!-- Compile the Source code -->
                      <target name="compile">
                         <echo message="compiling tests"/>
                          <mkdir dir="classes"/>
                              <javac debug="true" source="1.5"
                                     classpathref="build.classpath"
                                  srcdir="src"
                                  destdir="classes"/>
                      </target>

                   
                   <!-- Run the TestNG Test cases -->
              <!--     
                      <taskdef name="testng"
                       classname="com.beust.testng.TestNGAntTask"
                      classpathref="build.classpath"/>
                   
                        <path id="runpath">
                             <path refid="build.classpath"/>
                             <pathelement location="classes"/>
                        </path>
                   
                   <target name="test" depends="compile">
                        <echo message="running tests"/>
                             <testng fork="yes" classpathref="runpath" outputDir="test-output">
                                  <fileset dir="src" includes="testng.xml"/>
                                 <jvmarg value="-ea" />
                             </testng>
                   </target>

              -->     

                   <taskdef name="testng"
                       classname="org.testng.TestNGAntTask"
                      classpathref="build.classpath"/>

                        <path id="runpath">
                             <path refid="build.classpath"/>
                             <pathelement location="classes"/>
                        </path>
                   
                        <target name="test" depends="compile">
                             <echo message="running tests"/>
                             <taskdef resource="testngtasks" classpathref="build.classpath" />
                             <testng sourceDir="${src.dir}" outputdir="${test-output.dir}" classpathref="runpath">
                                  <xmlfileset dir="${src.dir}" includes="*.xml" />
                              </testng>
                        </target>
                   
              </project>

              -------------------------------------------------------

              Thank you,
              VK
              • 4. Re: Testing SEAM Application with TestNG
                Joseph Nusairat Newbie

                Maybe daniel can help you more, but i am having a difficult time understanding your question.


                The test you have right there is an integration test using the jboss embedded in the background.


                Is that not passing? Or are you asking if you shouldn't use it? What exactly are you trying to test?

                • 5. Re: Testing SEAM Application with TestNG
                  Vishnu Kommini Newbie
                  Hi Joseph,

                  I am not running any JBoss Embedded in background.

                  I have four methods in LoginTest.java. When I invoke testing.xml, it should call (run) those four methods. But when I run the ant build.xml, I get the below message in the console.

                  Buildfile: C:\TestNG BAISI Application\build_test.xml
                  compile:
                       [echo] compiling tests
                  test:
                       [echo] running tests
                     [testng] [Parser] Running:
                     [testng]   C:\TestNG BAISI Application\src\testng.xml
                     [testng] ===============================================
                     [testng] Test Suite
                     [testng] Total tests run: 0, Failures: 0, Skips: 0
                     [testng] ===============================================
                  BUILD SUCCESSFUL

                  Hope it is clear, please let me know, if you need any further info.

                  Thank you,
                  VK
                  • 6. Re: Testing SEAM Application with TestNG
                    Daniel Hinojosa Master
                    Looks like something is wrong with your build script...

                    It is looking at C:\TestNG BAISI Application\src\testng.xml still instead of testing.xml (note the i). Isn't testing.xml the file that should be processing?
                    • 7. Re: Testing SEAM Application with TestNG
                      Vishnu Kommini Newbie
                      Daniel,

                      you are correct. it was my typo mistake. I have created a file as testng.xml. since I have used *.xml in ant script, it pickup testng.xml to run.

                      infact I renamed testng.xml to testing.xml and ran the Ant Script, still I am getting same issue.

                      Buildfile: C:\BofA\TestNG BAISI Application\build_test.xml
                      compile:
                           [echo] compiling tests
                      test:
                           [echo] running tests
                         [testng] [Parser] Running:
                         [testng]   C:\BofA\TestNG BAISI Application\src\testing.xml
                         [testng] ===============================================
                         [testng] BOA Suite
                         [testng] Total tests run: 0, Failures: 0, Skips: 0
                         [testng] ===============================================
                      BUILD SUCCESSFUL
                      Total time: 1 second

                      -----------------------------

                      Thank you,
                      VK
                      • 8. Re: Testing SEAM Application with TestNG
                        Daniel Hinojosa Master

                        Well, there is still not much information for me to help without getting my hands on it.
                        So, let me post some items for you to look out for



                        • Classpath is incorrect or is in the incorrect order

                        • Your test class files cannot be found



                        Another question, are you using seam-gen's build.xml? or your own build.xml?