每當我們在@Test
帶註釋的方法上指定priority
和dependsOnMethods
時,測試方法的執行順序並不依據優先級。爲什麼如此? 下面是測試類來說明這個問題:當指定了dependsOnMethods時,testng未按優先級順序運行
package unitTest.TestNGTestCases;
import org.testng.annotations.Test;
public class TestNGTest1 {
@Test(priority=1)
public void t1()
{
System.out.println("Running 1");
}
@Test(priority=2,dependsOnMethods="t1")
public void t2()
{
System.out.println("Running 2");
}
@Test(priority=3,dependsOnMethods="t2")
public void t3()
{
System.out.println("Running 3");
}
@Test(priority=4)
public void t4()
{
System.out.println("Running 4");
}
}
實際輸出:
Running 1
Running 4
Running 2
Running 3
===============================================
All Tests Suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================
預期輸出:
Running 1
Running 2
Running 3
Running 4
===============================================
All Tests Suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================
測試執行的順序應該是T1,T2, t3,t4。爲什麼t4在t1之後執行,當t2和t3優先於t4?
TIA
您正在使用哪個版本的TestNG?根據[更改列表](https://github.com/cbeust/testng/blob/master/CHANGES.txt),您的問題似乎在2011年8月18日修復了6.2版。 – Seelenvirtuose
我正在使用6.8.8版本和testNG eclipse插件6.8.6。你可以嘗試上面的代碼,並證明它是按預期工作嗎? –
不幸的是,我不使用TestNG。 – Seelenvirtuose