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.
After changing the TestNG Output path(Project Properties-->TestNG-->Output Directory), its worked for me.
I was facing the same issue and what I tried is as below.
pom.xml
and clean)This solved the issue.
If you have your project open in Eclipse(Mars) IDE: Right click on the project in eclipse Click on TestNG Click on "Convert to TestNG"
This creates a new testng.xml file and prompts you to overwrite the existing one (!!!Warning, this will erase your previous testng.xml!!!). Click Yes.
Run as Maven test build.
I faced same problem but after close investigation.I found i was setting the class path wrong.
here what i was doing.
1-set class path=path for lib*; 2- java org.testng.TestNg testng.xml
Output-Cannot find class in classpath: tests.firstmodule
here firstmodule is my first class.
Solution
1-set class path=path for bin; lib*; 2- java org.testng.TestNg testng.xml
I ran into the same issue. Whenever I ran my test, it kept saying classes not found in the classpath. I tried to fix the testng.xml file, clean up the project and pretty much everything the answers say here, but none worked. Finally I checked my referenced libraries in build path and there were 34 invalid libraries, turns out I had renamed one of the folders from the path that I had taken the jar files from. I fixed the path and the test ran successfully.
So it might be fruitful to check if there are any errors in the referenced jar files before trying the other methods to fix this issue.
Eclipse ->Right Click on Project -> Build Path -> Configure -> Java Build Path.
Add Library -> JRE lib.
Add latest Java lib you are using in the system and remove other old JRE libs and save it.