TestNG教程

TestNG @AfterGroups

TestNG @AfterGroups Annotation

我们已经了解了@BeforeGroups 注解,它在执行属于参数中指定的组的测试方法之前执行@BeforeGroups 注解的方法@BeforeGroups 批注。
@AfterGroups: @AfterGroups 批注的方法只会在指定组的所有测试方法执行后运行一次。
我们通过一个例子来理解@AfterGroups注解:
第 1 步: 打开Eclipse。
第 2 步: 我们创建了一个简单的项目。
After_groups.java
package com.lidihuo;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.Test;
public class After_groups
{
@AfterGroups("Testing tool")
public void after_group()
{
System.out.println("The list which is shown above are the testing tools");
}
@Test(groups= {"Testing tool"})
public void testcase1()
{
System.out.println("Appium");
}
@Test(groups= {"Testing tool"})
public void testcase2()
{
System.out.println("JIRA");
}
@Test(groups= {"Testing tool"})
public void testcase3()
{
System.out.println("RedMine");
}
}
    
在上面的java项目中,我们已经创建了@AfterGroups注解的方法,并且我们传递了"TestingTool",这意味着@AfterGroups注解的方法,即after_group()将在所有属于的测试方法执行后被调用到"测试工具"组。
第 3 步: 现在,我们创建一个 testng.xml 文件来配置上述类。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="test_suite">
<test name="Testing tools">
<classes>
<class name="com.lidihuo.After_groups"/>
</classes>
</test> <!--Test-->
</suite> <!--Suite-->
    
第 4 步: 运行 testng.xml 文件。右键单击 testng.xml 文件,然后将光标向下移动到 运行方式,然后单击 1 TestNG 套件。
TestNG @AfterGroups Annotation
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4