Mru*_*sar 6 java testing testng automation
每当我们指定priority
,并dependsOnMethods
在@Test
注释的方法,测试方法执行的顺序不是根据优先级.为什么会这样?以下是演示该问题的测试类:
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");
}
}
Run Code Online (Sandbox Code Playgroud)
实际产量:
Running 1
Running 4
Running 2
Running 3
===============================================
All Tests Suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================
Run Code Online (Sandbox Code Playgroud)
预期产量:
Running 1
Running 2
Running 3
Running 4
===============================================
All Tests Suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================
Run Code Online (Sandbox Code Playgroud)
测试执行的顺序应该是t1,t2,t3,t4.为什么t4在t1之后执行,当t2和t3的优先级高于t4?
TIA
小智 7
所有独立的方法(没有 @dependsOnMethods 依赖项)将首先执行。然后将执行具有依赖关系的方法。如果即使在此排序之后执行顺序仍存在歧义,则优先级就会出现。
这是订购方案:
现在所有歧义都解决了,因为没有两个方法可以具有相同的名称。
小智 1
我今天遇到了同样的问题。
起初,我仅用于priority
测试,但后来我dependsOnMethods
也需要添加。
最初,我将dependsOnMethods
only 添加到了我的一些@Test
方法中。结果,我的测试的执行顺序被打乱了。
我读过很多与这个主题相关的文章和讨论,结果发现,使用 和priority
属性dependsOnMethods
一起给整个图片带来了很多不确定性,并且在这种情况下 TestNG 的行为永远无法预测和明确定义。
我的解决方案是将“添加”dependsOnMethods
到我的所有priority
测试方法中,同时为所有方法保留“ also”。现在他们的执行顺序恢复正常,同时我受益于dependsOnMethods
. 即链中第一个失败的测试方法导致所有后续测试方法被跳过并在报告中显示正确。
这是我的测试类的片段:
@Test(priority = 2, dependsOnMethods= {"Meganav_Point_C1_and_Click_C3"})
public void Click_product_in_Category_result_page() throws Throwable {
Grid.clickProduct(1, 1);
}
@Test(priority = 3, dependsOnMethods= {"Click_product_in_Category_result_page"})
public void PDP_setQty() throws Throwable {
ProductDetailsPage.setQty(2);
}
@Test(priority = 4, dependsOnMethods= {"PDP_setQty"}, alwaysRun= true)
public void PDP_click_Add_To_Basket() throws Throwable {
ProductDetailsPage.addToBasket();
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。
问候, 维塞林·彼得罗夫
归档时间: |
|
查看次数: |
7427 次 |
最近记录: |