簡體   English   中英

在TestNG中精細地運行測試類

[英]Running test classes granularly in TestNG

我的集成測試套件在TestNG上運行並利用其注釋。 在簡化的情況下,我有3個測試類,其中包含1個配置測試,並且其中一些依賴於配置測試。

TestClass1
  @Test()
  configureTestMethod() {}

  @Test(dependsOnMethods=["configureTestMethod"])
  testCase1_1() {}

  @Test(dependsOnMethods=["configureTestMethod"])
  testCase1_2() {}

TestClass2
  @Test()
  configureTestMethod() {}

  @Test(dependsOnMethods=["configureTestMethod"])
  testCase2_1() {}

  @Test(dependsOnMethods=["configureTestMethod"])
  testCase2_2() {}

TestClass3
  @Test()
  configureTestMethod() {}

  @Test(dependsOnMethods=["configureTestMethod"])
  testCase3_1() {}

  @Test(dependsOnMethods=["configureTestMethod"])
  testCase3_2() {}

我的問題是,當我運行所有這3個測試類時,它將按以下順序運行:TestClass1.configureTestMethod(),TestClass2.configureTestMethod(),TestClass3.configureTestMethod(),TestClass1.testCase1_1(),TestClass1.testCase1_2(),TestClass2 .testCase2_1(),TestClass2.testCase2_2(),...等等...

我知道這是有道理的,因為在不同類中的configureTestMethod()之間沒有依賴關系,因此對於TestNG,它們的順序不正確。

在繼續另一個測試類之前,如何運行測試類的所有測試方法?

我到目前為止發現的方向:

  1. 在不同的測試類中定義configureTestMethod()之間的依賴關系。 這意味着我不能運行單個測試類,因為它依賴於另一個測試類。

  2. 實現方法攔截器。 我到達那里三個configureTestMethod()方法,這對我來說執行順序無關緊要。 我想先運行他們的類方法,所以我確定如何在攔截器中控制它。

如果創建testing.xml文件,則默認情況下,其中提到的所有測試類將按照在其中提到的順序運行。 就是您想要的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM