我已经确定了测试用例的优先级,但是它们没有按照优先级顺序运行?请参考下面的代码。
public class TestngFeature {
WebDriver driver;
@Test(priority = 4, invocationCount = 5, alwaysRun = true, enabled = true)
public void TestCaseOne() {
System.out.println("TestCaseFirst -- This is First Test Case");
System.out.println("TestCaseOne -- This is first Test Case");
}
@Test(priority = 2, invocationTimeOut = 5, dependsOnMethods = "TestCaseOne")
public void TestCaseSecond() {
System.out.println("TestCaseSecond -- This is Second Test Case");
}
@Test(priority = 1, groups = { "Regression", "Smoke" }, dependsOnMethods = "TestCaseSecond")
public void TestCaseThird() {
System.out.println("TestCaseThird -- This is Third Test Case");
}
@Test(priority = 3, groups = { "Regression", "Sanity" })
public void TestCaseFourth() {
System.out.println("TestCaseFourth -- This is Fourth Test Case");
}
@Test(dependsOnGroups = "Regression")
public void TestCaseFifth() {
System.out.println("TestCaseFifth -- This is Fifth Test Case");
}
}
输出:
[RemoteTestNG] detected TestNG version 6.14.3
TestCaseFourth -- This is Fourth Test Case
TestCaseFirst -- This is First Test Case
TestCaseOne -- This is first Test Case
TestCaseFirst -- This is First Test Case
TestCaseOne -- This is first Test Case
TestCaseFirst -- This is First Test Case
TestCaseOne -- This is first Test Case
TestCaseFirst -- This is First Test Case
TestCaseOne -- This is first Test Case
TestCaseFirst -- This is First Test Case
TestCaseOne -- This is first Test Case
TestCaseSecond -- This is Second Test Case
TestCaseThird -- This is Third Test Case
TestCaseFifth -- This is Fifth Test Case
PASSED: TestCaseFourth
PASSED: TestCaseOne
PASSED: TestCaseOne
PASSED: TestCaseOne
PASSED: TestCaseOne
PASSED: TestCaseOne
PASSED: TestCaseSecond
PASSED: TestCaseThird
PASSED: TestCaseFifth
===============================================
Default test
Tests run: 9, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 9, Failures: 0, Skips: 0
===============================================
这就是我得到的结果。为什么它不遵循优先级,否则为什么优先级对TestNG起作用?
答案 0 :(得分:3)
因为您为dependsOnMethods
和TestCaseSecond
定义了TestCaseThird
。它的优先级高于priority
属性。来自testng Dependencies with annotations
您依赖的所有方法都必须已经运行并且成功运行
TestCaseFourth
的优先级最高(3),没有依赖性->它首先运行。
TestCaseOne()
在没有依赖关系的情况下具有次高优先级(4)->它运行第二次
TestCaseSecond()
在满足所有依赖项的情况下具有最高优先级(运行TestCaseOne
->它运行第三次
TestCaseThird()
在满足所有依赖性的情况下具有最高优先级(运行TestCaseSecond
->它运行第四位