之前一直是在Eclipse里运行测试的,本次简单介绍一下怎么样来实现命令行来执行TestNG。
Assuming that you have TestNG in your class path, the simplest way to invoke TestNG is as follows:1
java org.testng.TestNG testng1.xml [testng2.xml testng3.xml ...]
主要是在Windows下做的配置(有步骤已经做过,请忽略):
- 下载JDK安装,配置环境变量。
- 下载testng-6.8.8.jar包,放在C:\TestNG, 并配置了环境变量
- TESTNG_HOME 为 C:\TESTNG
- CLASSPATH 为 %CLASSPATH%;%TESTNG_HOME%\testng-6.8.jar;
在F:\testng下创建一个java文件command.java
1
2
3
4
5
6
7
8
9
10import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
public class A {
@Test
public void testAdd() {
String str = "TestNG is working fine";
assertEquals("TestNG is working fine", str);
}
}编译java文件
1
javac Command.java
在同目录下,创建testng.xml
1
2
3
4
5
6
7
8
9<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1">
<test name="test1">
<classes>
<class name="Command"/>
</classes>
</test>
</suite>使用java调用testng.xml
1
2
3
4
5
6
7
8F:\testng>java org.testng.TestNG testng.xml
[TestNG] Running:
F:\testng\testng.xml
===============================================
Suite1
Total tests run: 1, Failures: 0, Skips: 0
===============================================