如何从命令行运行TestNG [英] How to run TestNG from command line

查看:514
本文介绍了如何从命令行运行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 "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/TestNG
Caused 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。

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆