查看官网testng doc,给出以下命
令
java org.testng.TestNG testng1.xml [testng2.xml testng3.xml ...]
其中还提到,Assuming that you have TestNG in your class path, the simplest way to invoke TestNG is as follows:
需要将testNg加到classath中。
我们知道classpath是存放Java .class文件的地方,即编译的过的文件。因此我们需要把.jar文件,给注入的环境变量中。
一种是加到环境变量
另外一种,Java运行时,把依赖的class文件添加进来。
搜索到一个教程,如下:
- Install Java environment and set Java environment.
- Download TestNG archive, set TestNG environment and set the CLASSPATH for the testng.jar in the environment variables.
- Create a new folder “XTest”.
- Compile all your test classes and put them (.class files) in the folder “XTest”.
- Put your “testng.xml” and “.properties” files to “XTest”.
- Put your test data files to “XTest” (Remember to keep test data directory structure, or the test class will not find test data).
- Create a new subfolder “XTest\lib”.
- Put “testng.jar” and “jcommander.jar” to subfolder “XTest\lib”.
- Put all your test project dependent .jar files to subfolder “XTest\lib”.
- Browse to the folder “XTest” via command line and run the command
java -cp “lib*;” org.testng.TestNG testng.xml
这是是idea,编译好的class文件
这里是依赖的jar包,需要拷贝到Lib下
可以解压下Jar包看下,里面全是.class文件。 将某个jar包加入环境变量后,java命令就可以直接找到里面的class类,进行执行了。‘
比如最后命令的org.test.TestNG, 在testng的解压包路径是:
注意,必须把依赖的包都拷贝到Lib,不然可能报错。然后就可以用testNg 更多命令执行了。
最后贴一个工作目录,下面的class文件是idea编译出的,在target目录下的。