红联Linux门户
Linux帮助

ubuntu 16.04命令行执行testNG

发布时间:2016-12-10 10:25:12来源:linux网站作者:sinat_29052561
前提:仅仅下载testng.jar
 
不配置环境变量的前提下:
Java -cp "path-tojar/testng.jar:path_to_yourtest_classes" org.testng.TestNG testng.xml
 
配置环境变量:
export TESTNG_HOME=/home/peng/testng
export CLASSPATH=$CLASSPATH:$TESTNG_HOME/testng-6.8.6beta.jar
 
目录下执行 java org.testng.TestNG testng.xml
 
如出现下面错误:
Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
 
则是由于缺少jcommander.jar:http://central.maven.org/maven2/com/beust/jcommander/1.48/jcommander-1.48.jar
下载后在环境变量中添加:
export CLASSPATH=$CLASSPATH:$TESTNG_HOME/jcommander-1.48.jar
 
本文永久更新地址:http://www.linuxdiyf.com/linux/26763.html