一、安装jdk-8u191-windows-x64.exe
新建系统环境变量JAVA_HOME并配置Java搜索路径位置
二、安装IntelliJ IDEA
三、用New Project按钮创建工程(TestNG_Example)
四、安装TestNG和Create TestNG XML插件
五、如图创建一个Java类HelloWorld
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
public class HelloWorld {
@BeforeClass
public void Initiate() {
System.out.println("This is before class");
}
@AfterClass
public void FinalClose() {
System.out.println("This is after class");
}
@Test
public void Function1() {
System.out.println("This is TestNG test case1");
}
@Test
public void Function2() {
System.out.println("This is TestNG test case2");
}
@Test
public void Function3() {
System.out.println("This is TestNG test case3");
}
}
六、pom.xml文件配置如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>TestNG_Example</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
七、Create TestNG XML
八、全选用Ctrl+Alt+L格式化testng.xml
九、在testng.xml文件添加类HelloWorld
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Test Suite">
<test verbose="2" preserve-order="true" name="C:/project/TestNG_Example/src/test/java">
<classes>
<class name="HelloWorld"></class>
</classes>
</test>
</suite>