Wulf
Wulf

Reputation: 489

Eclipse TestNG: "Cannot find class in classpath" even when it's mapped with testng.xml

Using Java and Eclipse and TestNG, I've put together a simple Maven test automation framework project with a single test case class. But regardless of building and rebuilding and cleaning the project, every time I try running the test case from the test case class itself or from the testng.xml file, I get the dreaded "Cannot find class in classpath" error for my test class.

I've included two screenshots. The first has focus on my testng.xml file so you can see how my test class "SampleTest.java" is mapped. As you can see, it's mapped as <class name="src.test.java.myframework.SampleTest"/> but I've also tried <class name="test.java.myframework.SampleTest"/> and <class name="java.myframework.SampleTest"/> and <class name="myframework.SampleTest"/> but I get the same "Cannot find class" error no matter which path I use. I've even tried including .java to the end of the file name. I've also tried uninstalling TestNG and then reinstalling, building and cleaning the project multiple times, as well as quitting and restarting Eclipse to no avail.

In the second screenshot, I show my project's build path.

If someone could tell me what I'm doing wrong-- if anything, I would be most obliged!

Eclipse view of my testing.xml file and error console

Project Build path

Upvotes: 0

Views: 550

Answers (1)

Jayanth Bala
Jayanth Bala

Reputation: 838

Try without src/test/java, this is working for me. please ref screenshot,

enter image description here

<classes>
        <class name="myframework.SampleTest"/>
</classes>

if not please reinstall mvn and testng plugin

reference

Upvotes: 0

Related Questions