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.
make sure your suite.xml should not have .java extension
ex :
When I converted my project with default pacage and a class named addition, to testng.xml. It got converted as:
and was throwing error that class cannot be loaded. If I remove . before addition, the code works fine. So be careful with default package.
If your package name is FabFurnishPackage and your class name is registration then the code in xml should be
[TestNG] [ERROR] Cannot find class in classpath: registration issue is fixed...
Just do Eclipse> Project > Clean and then run the test cases again. It should work.
What it does in background is, that it will call mvn eclipse:clean in your project directory which will delete your .project and .classpath files and you can also do a mvn eclipse:eclipse - this regenerates your .project and .classpath files. Thus adding the desired class in the classpath.
I just had this problem and was because the skip test option in the run configuration was checked. made that unchecked and build, then run the testNg, worked.
I was facing the same issue,
Please check that
.java
&xml
file was created insrc
folder. CreatedTestNG
class by right clicking onsrc
folder. Works fine!