1、配置类
package com.course.testng.suite;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
public class SuiteConfig {
@BeforeSuite
public void beforeSuite(){
System.out.println("beforeSuite 已执行");
}
@AfterSuite
public void afterSuite(){
System.out.println("afterSuite 已执行");
}
@BeforeMethod
public void beforeMethod(){
System.out.println("beforeMethod 已执行");
}
@AfterMethod
public void afterMethod(){
System.out.println("afterMethod 已执行");
}
}
2、业务类一
package com.course.testng.suite;
import org.testng.annotations.Test;
public class LoginTest {
@Test
public void login(){
System.out.println("登录成功...");
}
}
3、业务类二
package com.course.testng.suite;
import org.testng.annotations.Test;
public class PayTest {
@Test
public void pay(){
System.out.println("支付成功...");
}
}
4、测试套件配置
<?xml version="1.0" encoding="UTF-8" ?>
<suite name="test">
<test name="login">
<classes>
<class name="com.course.testng.suite.SuiteConfig" />
<class name="com.course.testng.suite.LoginTest" />
</classes>
</test>
<test name="pay">
<classes>
<class name="com.course.testng.suite.SuiteConfig" />
<class name="com.course.testng.suite.PayTest" />
</classes>
</test>
</suite>
这里粗略的看下TestNG的约束文件,有些标签是需要指定的。
<!--
Here is a quick overview of the main parts of this DTD. For more information,
refer to the <a href="https://testng.org">main web site</a>.
A <b>suite</b> is made of <b>tests</b> and <b>parameters</b>.
A <b>test</b> is made of three parts:
<ul>
<li> <b>parameters</b>, which override the suite parameters
<li> <b>groups</b>, made of two parts
<li> <b>classes</b>, defining which classes are going to be part
of this test run
</ul>
In turn, <b>groups</b> are made of two parts:
<ul>
<li> Definitions, which allow you to group groups into
bigger groups
<li> Runs, which defines the groups that the methods
must belong to in order to be run during this test
</ul>
Cedric Beust & Alexandru Popescu
@title DTD for TestNG
@root suite
-->
如果需要在xml给出那些标签的提示可以加入如下约束头
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
执行结果: