[英]How do I make the control flow from one test class to another test class in testNG?
I have 4 test cases and I want the first test case to run from Demo1.java and then run the other 2 test cases from Demo2.java and then return back to Demo1.java to execute the final test case.我有 4 个测试用例,我希望第一个测试用例从 Demo1.java 运行,然后从 Demo2.java 运行其他 2 个测试用例,然后返回到 Demo1.java 以执行最终的测试用例。
Is there any way I can achieve this?有什么办法可以实现这一目标吗? Thanks for your help.
谢谢你的帮助。
priority
parameter but I guess that just checks for the priorities in the same test classpriority
参数,但我想这只是检查同一测试类中的优先级Here is a sample code -这是一个示例代码 -
Demo1.java Demo1.java
class Demo1{
@Test
public void testOne(){ //This case should be executed first
}
@Test
public void testFour(){ //This case should be executed last
}
}
Demo2.java Demo2.java
class Demo2{
@Test
public void testTwo(){ // This case should be executed 2nd in the order
}
@Test
public void testThree(){ // This case should be executed 3rd in the order
}
}
The combination of @dependsOnGroups and @dependsOnMethods annotations provides the most scalable way of test sequencing across classes and methods in TestNG. @dependsOnGroups和@dependsOnMethods注释的组合提供了 TestNG 中跨类和方法的测试排序的最具扩展性的方式。
Here is the working example using @dependsOnGroups and @dependsOnMethods:这是使用@dependsOnGroups 和@dependsOnMethods 的工作示例:
Scenario:设想:
ATest.java测试程序
public class ATest.java {
@Test(groups = "group-a1")
public void A1() {
System.out.println("Test A1: Runs before B1");
}
@Test(dependsOnGroups = "group-b2")
public void A2() {
System.out.println("Test A2: Runs after B2");
}
}
BTest.java测试程序
public class BTest {
@Test(dependsOnGroups = "group-a1")
public void B1() {
System.out.println("Test B1: Runs after A1");
}
@Test(dependsOnMethods = "B1", groups = "group-b2")
public void B2() {
System.out.println("Test B2: Runs after B1");
}
}
Note: The above sequencing can be implemented by using just the @dependsOnMethods annotation only.注意:上述排序可以仅通过使用@dependsOnMethods注释来实现。
However, it is not recommended to use @dependsOnMethods across classes, as it would make it mandatory to have unique name for each test case method in the entire suite.但是,不建议跨类使用@dependsOnMethods ,因为它会强制要求整个套件中的每个测试用例方法都具有唯一的名称。
The use of @dependsOnGroups will allow flexibility in test naming, and make it easy to implement sequencing across classes, without hassle.使用@dependsOnGroups将允许测试命名的灵活性,并可以轻松实现跨类的排序,没有麻烦。
More information:更多信息:
https://testng.org/doc/documentation-main.html https://testng.org/doc/documentation-main.html
Yes you can order Junit test Case by help of是的,您可以在以下人员的帮助下订购 Junit 测试用例
@FixMethodOrder(MethodSorters.JVM)
@TestMethodOrder(Alphanumeric.class)
@TestMethodOrder(OrderAnnotation.class)
@TestMethodOrder(TestCaseLengthOrder.class)
for details you can follow this link click for more detail turtorial有关详细信息,您可以点击此链接单击以获取更多详细信息教程
You can achieve by following below approach.您可以通过以下方法实现。
Class TEST1 extends Class TEST2 : TEST1 类扩展了 TEST2 类:
public class TEST1 extends TEST2{
@Test(priority = 1)
public void testOne() {
System.out.println("Test method one");
}
@Test(priority = 4)
public void testTwo() {
System.out.println("Test method two");
}
} }
Class TEST2 :类 TEST2 :
@Test(priority = 2)
public void testThree() {
System.out.println("Test three method in Inherited test");
}
@Test(priority = 3)
public void testFour() {
System.out.println("Test four method in Inherited test");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.