Java 错误:org.testng.TestNGException:在类路径中找不到类:EmpClass
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25543910/
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
Error: org.testng.TestNGException: Cannot find class in classpath: EmpClass
提问by user2991323
When i'm trying to run the test suite, am getting this exception. We are using maven project here and i am done with refreshing, cleaning, reinstalling testNG and then imported the maven projects but then also am getting the same exception. Please suggest any ways that am missing here.
当我尝试运行测试套件时,出现此异常。我们在这里使用 Maven 项目,我完成了刷新、清理、重新安装 testNG,然后导入了 Maven 项目,但随后也遇到了相同的异常。请提出这里缺少的任何方法。
Error console:
错误控制台:
org.testng.TestNGException:
Cannot find class in classpath: EmpClass
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:543)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:766)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1350)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2778)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:333)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
at org.testng.xml.XMLParser.parse(XMLParser.java:39)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
at org.testng.xml.Parser.parse(Parser.java:168)
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 Nael Marwan
You have to edit your tests Runner xml file. See this example:
您必须编辑您的测试 Runner xml 文件。看这个例子:
<test name="Employees Test">
<classes>
<class name="packagename.classname">
</class>
</classes>
</test>
In <class name="packagename.classname">
row you must enter your tests package name then name of class that you want to run.
在<class name="packagename.classname">
行必须输入要运行测试包的名称然后命名类。
Thanks and wish you all the best.
谢谢并祝你一切顺利。
回答by user3640657
I also got the same exception:
我也遇到了同样的异常:
I tried the following steps:
我尝试了以下步骤:
In Eclipse> Project > Clean. (The Exception remained)
I ran another project(The testng.xml ran successfully)
在 Eclipse > 项目 > 清理中。(例外仍然存在)
我运行了另一个项目(testng.xml 运行成功)
After running another project, I ran the project in which I was getting the Exception, and fortunately it worked for me, with no errors.
在运行另一个项目后,我运行了我得到异常的项目,幸运的是它对我有用,没有错误。
回答by Chinmoy
I had similar issue and the project had some build errors. I did sudo -R 777 to the project and then I cleaned my project. After that it worked fine.
我有类似的问题,该项目有一些构建错误。我对项目做了 sudo -R 777 ,然后我清理了我的项目。之后它工作得很好。
Hope it helps.
希望能帮助到你。
回答by Cláudio
I had the same error when tried to run my tests in a JSF project.
尝试在 JSF 项目中运行我的测试时,我遇到了同样的错误。
I′m using Eclipse IDE (kepler). So, I did "project > clean" and then ran the tests again of the same project.
我正在使用 Eclipse IDE(开普勒)。所以,我做了“项目>清理”,然后再次运行同一个项目的测试。
It worked!
有效!
回答by Key
Note: You have to specify class name along with packages as given below.
注意:您必须指定类名和包,如下所示。
<suite name="testNGLearning">
<test name="simpleTest">
<classes>
<class name="testngTests.TestNGSimpleTest" />
<class name="testngTests.TestMessageUtil" />
</classes>
</test>
</suite>
回答by Anthony Moon Beam Toorie
Got the IDE working again. The solution is quite funny - and even a re-install, and deleting the IDE does not fix it on windows. What you need to do in that case, is to go to the testNG run configurations - and delete them all. This is for the TestNG XML classpath error on windows OS. I am using spring tools suite 3.6.4.
让 IDE 再次工作。解决方案很有趣 - 甚至重新安装,删除 IDE 也不能在 Windows 上修复它。在这种情况下,您需要做的是转到 testNG 运行配置 - 并将它们全部删除。这是针对 Windows 操作系统上的 TestNG XML 类路径错误。我正在使用 spring 工具套件 3.6.4。
Make certain that you delete all the configurations, make sure the project can build, and if there are no problems, the test should run now.
确保删除所有配置,确保项目可以构建,如果没有问题,现在应该运行测试。
Regards -Anthony Toorie
问候-安东尼·托里
回答by zishan paya
I faced the similar issue on importing maven with testng project. This was solved by converting again into TestNg project by
我在使用 testng 项目导入 maven 时遇到了类似的问题。这是通过再次转换为 TestNg 项目解决的
right click on eclipse project > TestNG > Convert to TestNG
右键单击 eclipse 项目 > TestNG > 转换为 TestNG
and replacing the existing testng.xml
file with the newly created. Clean and update the maven project with mvn install
并用testng.xml
新创建的文件替换现有文件。使用以下命令清理并更新 Maven 项目mvn install
Note: take backup of your testng.xml
注意:备份你的 testng.xml
回答by Harish
In testng.xml file, remove "." from tag "" class name if you are not using packages.
在 testng.xml 文件中,删除“.” 如果您不使用包,则来自标签 "" 类名。
回答by Jitendra kumar
include the package name with class. It will remove your name. I also got the same issue but adding the package name with class fixed this issue.
在类中包含包名称。它会删除你的名字。我也遇到了同样的问题,但是在类中添加包名解决了这个问题。
回答by NateW
For me the problem was very strange.
I have a testng.xml file at the root of my Eclipse project. When I changed the file through Eclipse, it wasn't changing the testng.xml file in my directory.
对我来说,这个问题很奇怪。
我的 Eclipse 项目的根目录中有一个 testng.xml 文件。当我通过 Eclipse 更改文件时,它并没有更改我目录中的 testng.xml 文件。
Turns out it made a copy of the folder into the eclipse workspace..
原来它已将该文件夹的副本复制到 eclipse 工作区中..
Hope this helps someone out
希望这可以帮助某人