简体   繁体   English

TestNG-2个类之间的依赖关系(dependsOnGroups)

[英]TestNG - dependency between 2 Classes (dependsOnGroups)

I'm creating TestNG.xml programatically and running tests in parallel. 我正在以编程方式创建TestNG.xml并并行运行测试。

The issue is: - I need to run Test2 after Test1 问题是:-我需要在Test1之后运行Test2

I tried Using 'dependsOnGroup' by assigning Test1 to a group and then asking Test2 to dependOn Test1's group. 我尝试通过将Test1分配给一个组,然后要求Test2依赖于Test1的组来使用“ dependsOnGroup”。 But when I run the test suite, only Test1 will get Executed, Test2 will be skipped. 但是当我运行测试套件时,只有Test1将被执行,Test2将被跳过。 No errors reported. 没有错误报告。

@Test(groups = {"FirstTest"})
public class Test1 {

    public void hello(){
       syso("Test1");
    }
}

@Test(groups = {"SecondTest"}, dependsOnGroups= {"FirstTest"}, alwaysRun=true)
public class Test2 {

    public void hi(){
       syso("Test2");
    }
}

I'm using TestNG.6.9.6.jar 我正在使用TestNG.6.9.6.jar

Adding priority would do what you need. 添加优先级将满足您的需求。 @Test(priority=1) . @Test(priority=1) The lower priority would execute first. 较低优先级将首先执行。

@Test(priority=1)
public class Test1 {
public void hello(){
syso("Test1");
}
}

@Test(priority=2)
public class Test2 {
public void hi(){
syso("Test2");
}
}

It will first run Test1 and then Test2. 它将首先运行Test1,然后运行Test2。 So whichever classes you put in your test suite, it would consider the priorities of all the test functions in all it's classes. 因此,无论您将什么放入测试套件中,都将考虑其所有类别中所有测试功能的优先级。

Should do the needful for you in a lesser complicated way. 应该以较简单的方式为您做有需要的事情。

I hope it helps. 希望对您有所帮助。 :) :)

您也可以使用dependsOnMethods()方法代替dependsOnGroup()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM