java Mac 上的 TestNG 异常:在类路径中找不到类...!

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13601378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 13:22:34  来源:igfitidea点击:

TestNG Exception on Mac : Cannot find class in classpath...!

javatestng

提问by harish raja

When I am trying to run the test suite, am getting this exception on Mac, we are using maven projects here, today morning eclipse was hung and i done force quit and then restarted the same and later am not able to run the tests. I done refreshing, cleaning, reinstalling testNG, reconfigured eclipse with the new eclipse instance and imported the maven projects but then also am getting the same exception..The same maven projects ll run on the other Mac, Pls suggest any ways tat am missing here.

当我尝试运行测试套件时,在 Mac 上遇到此异常,我们在这里使用 Maven 项目,今天早上 Eclipse 挂起,我强制退出,然后重新启动相同,后来无法运行测试。我完成了刷新,清理,重新安装 testNG,使用新的 eclipse 实例重新配置 eclipse 并导入了 Maven 项目,但随后也遇到了相同的异常..相同的 Maven 项目将在另一台 Mac 上运行,请建议我在这里缺少的任何方法.

also referred the solutions present in the following links : SO link 1SO link 2

还提到了以下链接中的解决方案: SO 链接 1 SO 链接 2

Error console :

错误控制台:

org.testng.TestNGException: 
Cannot find class in classpath: com.adobe.store.polarBear.polarBearSuite.tests.ReaderAIHTest
    at org.testng.xml.XmlClass.loadClass(XmlClass.java:81)
    at org.testng.xml.XmlClass.init(XmlClass.java:73)
    at org.testng.xml.XmlClass.<init>(XmlClass.java:59)
    at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:539)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
    at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:788)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1343)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2756)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:1)
    at org.testng.xml.Parser.parse(Parser.java:172)
    at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:311)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

回答by bugCracker

Go to Project --> Clean

转到项目 --> 清理

It works for me

这个对我有用

回答by niharika_neo

Couple of suggestions : 1. Go to your target folder and check whether the .class for ReaderAIHTest is available? 2. Go to Run As - > Maven Build -> Enter goal as clean test-compile (I am assuming your cases are lying in src/test/java. )

几个建议: 1. 转到目标文件夹并检查 ReaderAIHTest 的 .class 是否可用?2. 转到 Run As -> Maven Build -> 输入目标为干净的测试编译(我假设您的案例位于 src/test/java 中。)

回答by niharika_neo

Are you using 'Run configurations' feature in eclipse ? If so, make sure you are using the correct testng.xml for the test you are trying to run. Sometimes you are using the wrong one or one that was autocreated in the 'Run Configurations' menu in eclipse.

您是否在 Eclipse 中使用“运行配置”功能?如果是这样,请确保您使用正确的 testng.xml 进行您尝试运行的测试。有时您使用了错误的一个或一个在 eclipse 的“运行配置”菜单中自动创建的。

回答by satish kumar poojari

if your package name is TEST_Packageand class name is DEMO_TESTthen the code in xml should be

如果你的包名是TEST_Package并且类名是DEMO_TEST那么 xml 中的代码应该是

classes
class name="TEST_Package.DEMO_TEST"
classes

you will try this......it will work

你会试试这个......它会起作用

回答by Bharat Bhagat

I faced the same problem. After syncing code from repo when i refreshed my project in eclipse. Package name start to show from src.test.java.com......

我遇到了同样的问题。当我在 Eclipse 中刷新我的项目时,从 repo 同步代码后。包名从src.test.java.com开始显示......

so the whole problem is .classpath file in your module directory Do 'mvn eclipse:eclipse' it will regenerate your module's '.classpath' file. And then refresh your project in eclipse.

所以整个问题是你的模块目录中的 .classpath 文件 Do 'mvn eclipse:eclipse' 它会重新生成你的模块的 '.classpath' 文件。然后在 eclipse 中刷新你的项目。

回答by Pedro Rosanes

For me, it was configured a wrong "Project compiler output". Go to File > Project Structure > Project compile output > Click in "..." > Choose a folder

对我来说,它配置了错误的“项目编译器输出”。转到文件 > 项目结构 > 项目编译输出 > 单击“...” > 选择一个文件夹

回答by palslav

For IntelliJ Idea, after re-building the project use command : mvn idea:idea

对于 IntelliJ Idea,在重新构建项目后使用命令:mvn idea:idea

After Build success, the exception "Cannot find class in classpath" is resolved.

Build成功后,“Cannot find class in classpath”异常得到解决。