TestNG ERROR: Cannot find class in classpath after compiling the maven project

TestNG ERROR: Cannot find class in classpath after compiling the maven project

我正在使用 maven 项目,在我编译和发布该项目之前,所有 testNG 测试都正常工作。现在,当我在 eclipse

中执行测试时,出现错误 "Cannot find class in classpath"

测试class在/src/test/java

下面是我的样本测试 xml:

<suite name="Testing1" parallel="false" verbose="10">
    <test name="Test1">
        <classes>
            <class name="com.test.TestClass"/>
        </classes>
    </test>
</suite>

谁能告诉我为什么它不再工作了?

只需执行 Eclipse> 项目 > 清理,然后再次 运行 测试用例。它应该工作。

它在后台所做的是,它将在您的项目目录中调用 mvn eclipse:clean,这将删除您的 .project 和 .classpath 文件,您也可以执行 mvn eclipse:eclipse - 这会重新生成您的 .project 和 .classpath 文件。因此在 class 路径中添加所需的 class。