1

I have following code snippet-

Class 1 :- DependencyOne.java

public class DependencyOne 
{
   @Test(groups = "xxx")
   public void parentTestMethodOne()
   {
        System.out.println("parent Test Method One");
   }
   @Test(groups = "vizac")
  public void parentTestMethodTwo()
  {
      System.out.println("parent Test Method Two");
  }
  @Test(groups = "xxx")
  public void parentTestMethodThree()
  {
      System.out.println("parent Test Method Three");
  } 
}

And The another class is

Class 2 :- DependencyTwo.java

public class DependencyTwo 
{

   @Test(dependsOnMethods = "testMethodThree")
   public void testMethodOne()
   {
      System.out.println("Test Method One");
   }
   @Test(dependsOnGroups = "xxx")
   public void testMethodTwo()
  {
     System.out.println("Test Method Two");
  }
    @Test(dependsOnMethods = "testMethodTwo")
    public void testMethodThree()
    {
       System.out.println("Test Method Three");
    }
}

When I'm executing the DependencyTwo it is giving following output -

  • parent Test Method One
  • parent Test Method Three
  • parent Test Method Two
  • Test Method Two
  • Test Method Three
  • Test Method One

    And what I'm expecting is-

  • parent Test Method One
  • parent Test Method Three
  • Test Method Two
  • Test Method Three
  • Test Method One

    Can any one please explain me why it is happening even I'm accessing only specified group's test methods of other class and Please suggest me how can I access only group specified test methods in other class.

    enter image description here

  • NarendraR
    • 7,577
    • 10
    • 44
    • 82
    • Which testng are you using? How do you run your test? What is the relation between DependencyOne and DependencyTwo? – juherr Nov 14 '16 at 08:11
    • I'm using TestNG 6.9.10 libraries and executing the class directly (as a TestNg Test) where I have placed all methods e.g. DependencyTwo.but there are some common methods which are placed in another class e.g DependencyOne .common methods categorized with group in DependencyOne class and I need to call all methods of that particular group before a test method in DependencyTwo class – NarendraR Nov 14 '16 at 08:25
    • Both classes are in same package – NarendraR Nov 14 '16 at 08:31
    • I still don't understand how you run your test. If you run all classes without a group filter then all methods will be run. – juherr Nov 14 '16 at 09:31
    • I have attached screenshot .I'm executing DependencyTwo as a TestNG class – NarendraR Nov 14 '16 at 09:51
    • Here i have made group filter as expected to call all methods of xxx group from DependencyOne class as In only call DependencyTwo class – NarendraR Nov 14 '16 at 10:04
    • @NarendraRajput - I think you should maybe create a suite xml file that shows how you are intending to call your test classes. That way there's no guess work for others. – Krishnan Mahadevan Nov 15 '16 at 07:37

    1 Answers1

    2

    One alternative so far I know

    Just create one testing.xml file where you can manage your methods which you want to include/exclude-

    Use following in your xml file -

    <test name="MyTest">
        <groups>
            <run>
                <exclude name="vizac"/>
            </run>
        </groups>
        <classes>
            <class name="com.flipkart.DependencyOne" />
            <class name="com.flipkart.DependencyTwo" />
        </classes>
    </test>
    
    Nik
    • 204
    • 3
    • 20