TestNG ERROR Cannot find class in classpath

2019-01-14 15:37发布

I'm trying to run testng via command line and I have following things in classpath:

  • testng jar, jar of compiled test case file, and other required jars.
  • testng.xml points to appropriate class in the hierarchy.

Testng doesn't run instead it throws:

[TestNG] [ERROR]  Cannot find class in classpath: (name of testcase file)

I encountered the same issue before and I just added.

In classpath and it solved the problem. But this time it did not seem to solve it. Any workarounds? Thanks in advance.

30条回答
乱世女痞
2楼-- · 2019-01-14 16:13

simple solution was to remove .java extension from class path name. and it worked for me

查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-14 16:15

Update TestNG plugin and It will work.

查看更多
迷人小祖宗
4楼-- · 2019-01-14 16:15

Please make sure that you have specified your class/package in TestNG.xml file.

<test name="test1" preserve-order="false">
    <classes>
        <class name="ABC"/>
    </classes>
</test>

查看更多
男人必须洒脱
5楼-- · 2019-01-14 16:16

Before running the command for testng.xml file from command prompt, please check the following if you are missing them

  1. In the command prompt, make sure you are navigating to the folder where you have placed the testng.xml file.
  2. after navigating to that, set CLASSPATH and include the testng jar file location, selenium-server jar file location(if you are working with selenium webdriver), bin folder location of your project which contains all the .class files of your project.
    e.g., set CLASSPATH=C:\Selenium\testng-5.8-jdk15.jar;C:\Selenium\selenium-server-standalone-2.31.0.jar;C:\SeleniumTests\YourProject\bin
  3. Now run the command java org.testng.TestNG testng.xml.

I was into the same situation but the above things worked for me.

查看更多
We Are One
6楼-- · 2019-01-14 16:16

I had to make a jar file from my test classes and add it to my class path. Previously I added my test class file to class path and then I got above error. So I created a jar and added to classpath.

e.g

java -cp "my_jars/*" org.testng.TestNG testing.xml
查看更多
Evening l夕情丶
7楼-- · 2019-01-14 16:17

This issue is coming due to some build error. 1. Clean Project - if issue not resolve 2. update maven project - If still not resolved 3. Go to build path from (right click on project- > properties -> java build path) now check library files. if you see an error then resolve it by adding missing file at given location.

I face the same issue, after lots of approaches I found 3rd solution to get that issue fixed

查看更多
登录 后发表回答