我可以在一种TestNG情况下多次使用@BeforeClass吗?

时间:2019-01-03 08:31:25

标签: testng

BusinessObjectType

如果我在一个TestNG类上使用两次'@BeforeClass',这两种方法的顺序是什么?我可以指定两种方法的顺序吗?

2 个答案:

答案 0 :(得分:1)

是的,您可以在一个类中添加多个@BeforeClass方法。它们将按照方法名称的字母顺序运行,例如在下面的示例中,执行顺序为

  1. setUp1()
  2. setUp2()
  3. queryAcquirerInfoById()

public class TestBase{

     @BeforeClass
     protected void setUp2() throws Exception {}

     @BeforeClass
     protected void setUp1() throws Exception {}

      @Test
      public void queryAcquirerInfoById(){
            }
        }

但是,您可以使用'dependsOnMethods'选项确定@BeforeClass方法的执行优先级,就像您编写


public class TestBase{

     @BeforeClass (dependsOnMethods = { "setUp1" })
     protected void setUp2() throws Exception {}

     @BeforeClass
     protected void setUp1() throws Exception {}

      @Test
      public void queryAcquirerInfoById(){
            }
        }

然后setUp1()将在setUp2()之前运行

答案 1 :(得分:0)

当时是asked in testng group,建议使用单个方法按所需顺序调用多个方法:

  

使用最简单的方法:

cv2.__version__

以您的情况

3.3.0
相关问题