简体   繁体   中英

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!

我的 testing.xml 文件和错误控制台的 Eclipse 视图

项目构建路径

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

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM