📜  TestNG @BeforeGroups批注

📅  最后修改于: 2021-01-11 12:05:55             🧑  作者: Mango

TestNG @BeforeGroups批注

TestNG允许测试人员通过使用@Test批注中的属性'group'将多个测试用例创建到一个组中。我们可以说TestNG组允许您在同一组中添加类似的功能。例如,student_id,student_name,student_address是学生的详细信息,并且所有这些详细信息都添加在同一组中,即“学生详细信息”。

@BeforeGroups: @BeforeGroups注释的方法仅在执行属于指定组的所有测试方法之前运行一次。

让我们通过示例了解@BeforeGroups批注。

步骤1:打开Eclipse。

步骤2:我们创建一个简单的Java项目。

Class1.java

package com.javatpoint;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
public class Class1 
{
@BeforeGroups("IT Department")
public void before_it()
{
System.out.println("This method will be executed before the execution of IT Department group");
}
@Test
public void testcase1()
{
System.out.println("HR");
}
 @Test(groups= {"IT Department"})
public void testcase2()
{
System.out.println("Software Developer");
}
@Test(groups= {"IT Department"})
public void testcase3()
{
System.out.println("QA Analyst");
}
}

在上面的代码中,我们创建了一个Java项目,其中定义了@BeforeGroups批注方法,在@BeforeGroups中,我们传递了“ IT部门”,这意味着@BeforeGroups批注方法,即before_it()将在执行属于“ IT部门”组的所有测试方法。

步骤3:现在,我们创建一个testng.xml文件来配置上面的类。

testng.xml文件








 
 

步骤4:运行testng.xml文件。右键单击testng.xml文件,将光标向下移动到Run As ,然后单击1 TestNG Suite