我如何从命令行运行.java TestNG项目?我已经阅读了TestNG文档,并尝试了以下操作但无济于事:C:\projectfred> java org.testng.TestNG testng.xml...在我的项目中带有以下testng.xml文件:<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="SuiteAll" verbose="1">
<test name="TestAll">
<packages>
<package name="com.project.fred.tests"/>
</packages>
</test> </suite>我得到的错误是这样的:Exception in thread "main" java.lang.NoClassDefFoundError: org/testng/TestNGCaused by: java.lang.ClassNotFoundException: org.testng.TestNG
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)Could not find the main class: org.testng.TestNG. Program will exit.显然,我在命令行中没有正确引用TestNG。有谁知道如何使它工作?
3 回答
白板的微信
TA贡献1883条经验 获得超3个赞
非常感谢。它确实非常有帮助。我能够使用命令行运行TestNG类,但我还是想最后一次总结一下这些内容。
1) Set the classpath for the testng.jar in the environment variables(either manually or via command line).2) Create a new folder "MyTest".3) Compile all your classes(testNG+java) and put them(.class files )in a new folder "Mytest\bin".4) Put your 'testng.xml' and '.properties' files to "Mytest\bin"again.5) Put all the .jar files (testng,selenium... etc) in a new folder"Mytest\lib".6) Browse to the folder "bin" via command line and run the command java -cp "..\lib\*;" org.testng.TestNG testng.xml
这应该运行您的testNG案例。
添加回答
举报
0/150
提交
取消