NarendraR
NarendraR

Reputation: 7708

Executing all test methods of a class while accessing only particular group of that class in TestNG

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

    Upvotes: 1

    Views: 117

  • Answers (1)

    Nik
    Nik

    Reputation: 204

    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>
    

    Upvotes: 2

    Related Questions