2

Previously I am using testng 6.8.8 version and all tests are executed as expected. But before a few days back I updated testng version to 6.14.2, Started facing running sequences issue. I also tried with priority change and all things but it's not working as it was working in testng 6.8.8. Refer source code for more details.

class1.java

    package TestNG;

    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.Test;
    public class class1
    {
    @BeforeClass
    public void beforeclass1()
    {
        System.out.println("before_class1");

    }

    @AfterClass
    public void afterclass1()
    {
        System.out.println("after_class1");

    }

    @Test(priority = 0)
    public void class1_method1()
    {
        System.out.println("class1_method1");
    }

    @Test(priority = 1)
    public void class1_method2()
    {
        System.out.println("class1_method2");

    }

    @Test(priority = 2)
    public void class1_method3()
    {
        System.out.println("class1_method3");

    }
}

class2.java

package TestNG;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class class2
{

    @BeforeClass
    public void beforeclass1()
    {
        System.out.println("before_class2");

    }

    @AfterClass
    public void afterclass1()
    {
        System.out.println("after_class2");

    }

    @Test(priority = 0)
    public void class2_method1()
    {
        System.out.println("class2_method1");
    }

    @Test(priority = 1)
    public void class2_method2()
    {
        System.out.println("class2_method2");

    }

    @Test(priority = 2)
    public void class2_method3()
    {
        System.out.println("class2_method3");

    }
}

class3.java

package TestNG;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class class3
{

    @BeforeClass
    public void beforeclass1()
    {
        System.out.println("before_class3");

    }

    @AfterClass
    public void afterclass1()
    {
        System.out.println("after_class3");

    }

    @Test(priority = 0)
    public void class3_method1()
    {
        System.out.println("class3_method1");
    }

    @Test(priority = 1)
    public void class3_method2()
    {
        System.out.println("class3_method2");

    }

    @Test(priority = 2)
    public void class3_method3()
    {
        System.out.println("class3_method3");

    }
}

testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test" >
    <classes>
      <class name="TestNG.class1">
        <methods>
          <include name="class1_method1"/>
          <include name="class1_method2"/>
          <include name="class1_method3"/>
          <include name="beforeclass1"></include>
          <include name="after_class1"></include>
          </methods>
      </class>
      <class name="TestNG.class2">
       <methods>
          <include name="class2_method1"/>
          <include name="class2_method2"/>
          <include name="class2_method3"/>
          <include name="beforeclass2"></include>
          <include name="after_class2"></include>         
          </methods>
      </class>
      <class name="TestNG.class3">
          <methods>
          <include name="class3_method1"/>
          <include name="class3_method2"/>
          <include name="class3_method3"/>
          <include name="beforeclass3"></include>
          <include name="after_class3"></include>
          </methods>
       </class>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Actual Output after running testng.xml using testng(6.14.2):

before_class1

class1_method1

before_class2

class2_method1

before_class3

class3_method1

class1_method2

class2_method2

class3_method2

class1_method3

after_class1

class2_method3

after_class2

class3_method3

after_class3

Expected Output :(Working fine with testng 6.8.8 but not working in testng 6.14.2)

before_class1

class1_method1

class1_method2

class1_method3

after_class1

before_class2

class2_method1

class2_method2

class2_method3

after_class2

before_class3

class3_method1

class3_method2

class3_method3

after_class3

1 Answers1

0

This setup will work till 6.9.10, after that priority is global for a test tag.

Use dependsOnMethods or depednsOnGroups to run in order first inside a class. You will need to use alwaysRun = true if you want to run the method if the method it depends on fails.

Also you can try just splitting the classes into different test tags.

Also not sure if there is a need to mention the before and after methods in the methods tag.

Grasshopper
  • 8,908
  • 2
  • 17
  • 32