Mac OS command line TestNG - “Cannot find class in classpath” error

直接eclipse执行.xml文件可以正确执行

在mac下执行却总报错:

[TestNG] [Error]

Cannot find class in classpath

最后解决办法,classpath格式错误,正确执行的格式:

先cd 到工程目录,

java -cp "lib/testng-6.9.10.jar:bin:lib/:target/test-classes/"   -Djava.ext.dirs=lib  org.testng.TestNG testSuits/testSuitExample_android.xml

 

lib  bin  target都是工程下的文件夹,

其中.class文件在target/test-classes/下,lib下是一些引用的jar包,待执行的文件testSuitExample_android.xml在testSuits目录下

mac下用:分隔;windows下用;分隔

 

详细的如何下dos prompt下执行TestNG见下面链接:

http://stackoverflow.com/questions/11896791/how-to-run-testng-from-dos-prompt

 

You need to have the testng.jar under classpath.

try C:\projectfred> java -cp "path-tojar/testng.jar:path_to_yourtest_classes" org.testng.TestNG testng.xml

Update:

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

Directory structure:

/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.

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:

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

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

转载于:https://www.cnblogs.com/melody-emma/p/5212769.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值