当我做项目时,TestNG 测试用例没有编译 ->干净的
我正在使用 Spring、TestNG、Eclipse、Maven、Mac OS
场景
我正在对我的测试用例( TestNG 测试用例)进行一些更改,
然后我做 Project ->在 Eclipse 中清理
现在我正在运行测试文件,但更改未更新。
我怀疑测试文件没有编译。
我可以运行服务器,也可以运行我的网络服务,
但是如果我运行 Maven 测试( mvn test ),整个代码都会编译,包括测试用例。
因此,为了运行测试用例,我仅运行 mvn test 命令。
无法通过eclipse运行。
Eclipse 配置:
自动构建
在 Java 构建路径中包含测试包
如果您需要更多信息,我将提供。
org.testng.TestNGException:
Cannot find class in classpath: com.***.***.model.***.case.CaseModelImplTest
at org.testng.xml.XmlClass.loadClass(XmlClass.java:76)
at org.testng.xml.XmlClass.init(XmlClass.java:68)
at org.testng.xml.XmlClass.<init>(XmlClass.java:54)
at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:512)
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:2755)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
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:10)
at org.testng.xml.Parser.parse(Parser.java:170)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:304)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:86)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:199)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:170)
I am using Spring, TestNG, Eclipse, Maven, Mac OS
Scenario is
I am doing some changes in my test cases ( TestNG test cases ),
Then i do Project -> Clean in eclipse
Now i am running the test file, but the changes not updated.
I suspects that the test files are not compiled.
I can run the server and i can run my webservices
But if i run maven test ( mvn test ), the entire code is compiling including test cases.
So to run the test cases i am running mvn test command only.
Not able to run through eclipse.
Eclipse config:
Auto build on
In Java build path the test package is included
If you need any more info i'll provide.
org.testng.TestNGException:
Cannot find class in classpath: com.***.***.model.***.case.CaseModelImplTest
at org.testng.xml.XmlClass.loadClass(XmlClass.java:76)
at org.testng.xml.XmlClass.init(XmlClass.java:68)
at org.testng.xml.XmlClass.<init>(XmlClass.java:54)
at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:512)
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:2755)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
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:10)
at org.testng.xml.Parser.parse(Parser.java:170)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:304)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:86)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:199)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:170)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
看来,您没有将您的测试用例类包括在构建路径中。右键单击您的项目文件夹,转到项目 properties-&gt; src
通过检查它来包括您的TestCase SRC文件夹。
现在应该运行。
It seems , you are not included your Test case class into the build path. Right click on your Project folder, go to the project properties->src
include your Testcase src folder by checking it.
Now it should run.
打开问题视图。在 Eclipse 中,转到“窗口”->“显示视图”->“问题”。它会列出编译代码时的所有失败。
Open the Problems view. In Eclipse go to Window->Show View->Problems. It will list out all the failures while compiling the code.
测试用例是否正在编译,但到了错误的目录?它们需要编译为测试类而不是类。在构建路径中,您需要将输出文件夹设置为
对于所有测试资源(包括 src/test/java 和 src/test/resources)都是如此。
在 Eclipse 中编辑项目属性,选择 Java 构建路径,然后在“源”选项卡中,您将看到所有源目录。每个都有一个输出文件夹。该输出文件夹需要如上所示。
Are the test cases being compiled, but to the wrong directory? They need to be compiled to test-classes not classes. In your build path, you need to set your Output folder to be
This is true for all test resources (including src/test/java & src/test/resources).
Edit your project properties in Eclipse, select
Java Build Path
, and then in the Source tab, you'll see all of your source directories. Each one has an output folder. This output folder needs to be as above.转到
项目 --> Clean
这对我有类似的问题有用。
Go to
Project --> Clean
That worked for me with similar problem.
请检查您的
testNG.xml
文件以获得正确的测试,因为我遇到了相同的错误,这是因为输入了错误的测试名称。Please check your
testNG.xml
file for correct test because I got the same error and it was because the wrong test name was entered.您的测试文件夹是否添加为 Eclipse 中的源文件夹?如果不是,它将不会包含在构建中。
is your test folder added as a source folder in Eclipse? If it isn't it won't be included in the build.
我通过以下方法解决了这个问题:
I solved this by:
我想有时如果您的测试类位于默认包和 Testng.xml 中,我们会收到此错误,您指定如下 -
在上面,我将我的测试类从默认包移动到某个包,并更新了 testng.xml,如下所示 - 一切都开始工作。
我希望这对您有帮助...如果问题仍然存在,请尝试上述选项。
谢谢!
I think some time we get this error if your test class is in default package and in Testng.xml, you specify as below -
Here in above, I moved my testclass from default package to some package and also updated testng.xml as below - and everything started working.
I hope this helps you... if issue still exists, try above options.
thanks!
检查您的项目工件(如 excel、属性文件、xml 文件等)是否在文本编辑器等中打开(如果是,请关闭它们并进行重建)
当您清理和重建时,请确保所有项目相关文件都已关闭并进行构建。
Check if your project artifacts like excel, property files, xml files etc are open in text editors etc. ( if yes please close them and do rebuild )
When you clean and rebuild make sure all project dependent files are closed and you do build.