TestNG order of execution of test case with priority

The following are test methods in the TestNGtest case class :

@Test (priority=0)
public void test01() {
}
@Test (priority=1, dependsOnMethods="test01")
public void test02() {
}
@Test (priority=2)
public void test03() {
}
@Test (priority=3)
public void test04() {
}

Execution order test01 - test03 - test04 - test02. Well, that seems wrong, because by the time it is reached test02, the dependent test method is already running test01. Therefore, it test02should be done immediately. I believe the correct ordertest01 - test02 - test03 - test04

Is this an error in TestNG, or is intentionally for some reason that I do not have enough?

+4
source share
2 answers

Do not give priority, and depending on whether you can group tests. You can do it like:

@Test(priority = 1, groups = { "qty" })
public void increaseQty() {
    System.out.println("in increase qty");
}

@Test(dependsOnMethods = { "increaseQty" }, groups = { "qty" })
public void decreaseQty() {
    System.out.println("in decrease qty");
}

@Test(dependsOnGroups = { "qty" })
public void removeFromCart() throws Exception {
    System.out.println("remove qty");
}

@Test(dependsOnMethods = { "removeFromCart" })
public void emptyCart() throws InterruptedException {
    System.out.println("empty Cart");
}
0

Source: https://habr.com/ru/post/1653680/


All Articles