Order of execution of tests in TestNG

前端 未结 17 2709
情书的邮戳
情书的邮戳 2020-11-27 12:46

How to customize the order of execution of tests in TestNG?

For example:

public class Test1 {
  @Test
  public void test1() {
      System.out.printl         


        
17条回答
  •  醉酒成梦
    2020-11-27 13:28

    An answer with an important explanation:

    There are two parameters of "TestNG" who are supposed to determine the order of execution the tests:

    @Test(dependsOnGroups= "someGroup")
    

    And:

    @Test(dependsOnMethods= "someMethod")
    

    In both cases these functions will depend on the method or group,

    But the differences:

    In this case:

    @Test(dependsOnGroups= "someGroup")
    

    The method will be dependent on the whole group, so it is not necessarily that immediately after the execution of the dependent function, this method will also be executed, but it may occur later in the run and even after other tests run.

    It is important to note that in case and there is more than one use within the same set of tests in this parameter, this is a safe recipe for problems, because the dependent methods of the entire set of tests will run first and only then the methods that depend on them.

    However, in this case:

    @Test(dependsOnMethods= "someMethod")
    

    Even if this parameter is used more than once within the same set of tests, the dependent method will still be executed after the dependent method is executed immediately.

    Hope it's clearly and help.

提交回复
热议问题