如何从命令行运行TestNG

编程入门 行业动态 更新时间:2024-10-27 09:45:27
本文介绍了如何从命令行运行TestNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我如何从命令行运行.java TestNG项目?

How exactly do I run a .java TestNG project from a command line?

我已经阅读过TestNG文档,并尝试下列方法无效: / p>

I have read through the TestNG documentation, and tried the following to no avail:

C:\projectfred> java org.testng.TestNG testng.xml

...在我的下面有testng.xml文件项目:

... with the following testng.xml file in my project:

<!DOCTYPE suite SYSTEM "testng/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/TestNG Caused by: java.lang.ClassNotFoundException: org.testng.TestNG at java.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.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。

Obviously, I am not referencing TestNG correctly in my command line. Does anyone know how to get this working?

推荐答案

你需要有 testng.jar 在类路径下。

try C:\projectfred> java -cppath-tojar / testng.jar:path_to_yourtest_classesorg.testng.TestNG testng.xml

更新:

在linux下,我运行这个命令,这将是Windows上类似的东西

Under linux I ran this command and it would be some thing similar on Windows either

test/bin# java -cp ".:../lib/*" org.testng.TestNG testng.xml

目录结构:

/bin - All my test packages are under bin including testng.xml /src - All source files are under src /lib - All libraries required for the execution of tests are under this.

一旦我编译了所有的源代码,所以,在类路径中,我需要指定内容的bin目录和所有的库像testng.xml,日志记录器等在这里。如果您不想指定testng.xml可用的完整路径,也可以将testng.xml复制到bin文件夹。

Once I compile all sources they go under bin directory. So, in the classpath I need to specify contents of bin directory and all the libraries like testng.xml, loggers etc over here. Also copy testng.xml to bin folder if you dont want to specify the full path where the testng.xml is available.

/bin -- testng.xml -- testclasses -- Properties files if any. /lib -- testng.jar -- log4j.jar

更新:

Update:

转到 MyProject 并键入运行java命令,如下所示: -

Go to the folder MyProject and type run the java command like the way shown below:-

java -cp ".: C:\Program Files\jbdevstudio4\studio\plugins\*" org.testng.TestNG testng.xml

我相信testng.xml文件在 C:\Users\me\workspace\MyProject 如果没有请给 testng.xml 文件

I believe the testng.xml file is under C:\Users\me\workspace\MyProject if not please give the full path for testng.xml file

更多推荐

如何从命令行运行TestNG

本文发布于:2023-11-13 21:53:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585419.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令行   TestNG

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!