当我做项目时,TestNG 测试用例没有编译 ->干净的

发布于 2024-12-04 10:25:00 字数 2894 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

浮光之海 2024-12-11 10:25:00

看来,您没有将您的测试用例类包括在构建路径中。右键单击您的项目文件夹,转到项目 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.

叹沉浮 2024-12-11 10:25:00

打开问题视图。在 Eclipse 中,转到“窗口”->“显示视图”->“问题”。它会列出编译代码时的所有失败。

Open the Problems view. In Eclipse go to Window->Show View->Problems. It will list out all the failures while compiling the code.

梦回梦里 2024-12-11 10:25:00

测试用例是否正在编译,但到了错误的目录?它们需要编译为测试类而不是类。在构建路径中,您需要将输出文件夹设置为

项目/目标/测试类

对于所有测试资源(包括 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

PROJECT/target/test-classes

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.

眼泪也成诗 2024-12-11 10:25:00

转到项目 --> Clean

这对我有类似的问题有用。

Go to Project --> Clean

That worked for me with similar problem.

所谓喜欢 2024-12-11 10:25:00

请检查您的 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.

小镇女孩 2024-12-11 10:25:00

您的测试文件夹是否添加为 Eclipse 中的源文件夹?如果不是,它将不会包含在构建中。

is your test folder added as a source folder in Eclipse? If it isn't it won't be included in the build.

情场扛把子 2024-12-11 10:25:00

我通过以下方法解决了这个问题:

  1. 更改构建路径/删除一些错误的路径
  2. 清理项目

I solved this by:

  1. Changing the build path / deleting some of the wrong ones
  2. Cleaning the project
笔芯 2024-12-11 10:25:00

我想有时如果您的测试类位于默认包和 Testng.xml 中,我们会收到此错误,您指定如下 -

<suite name="Suite" parallel="none">
<listeners>
    <listener class-name="org.uncommons.reportng.HTMLReporter" />
    <listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
<test name="Test">
    <classes>
        <class name=".Test1" />
    </classes>
</test> <!-- Test -->

在上面,我将我的测试类从默认包移动到某个包,并更新了 testng.xml,如下所示 - 一切都开始工作。

<suite name="Suite" parallel="none">
<listeners>
    <listener class-name="org.uncommons.reportng.HTMLReporter" />
    <listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
<test name="Test">
    <classes>
        <class name="com.sigma.rest.api.Test1" />
    </classes>
</test> <!-- Test -->

我希望这对您有帮助...如果问题仍然存在,请尝试上述选项。

谢谢!

I think some time we get this error if your test class is in default package and in Testng.xml, you specify as below -

<suite name="Suite" parallel="none">
<listeners>
    <listener class-name="org.uncommons.reportng.HTMLReporter" />
    <listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
<test name="Test">
    <classes>
        <class name=".Test1" />
    </classes>
</test> <!-- Test -->

Here in above, I moved my testclass from default package to some package and also updated testng.xml as below - and everything started working.

<suite name="Suite" parallel="none">
<listeners>
    <listener class-name="org.uncommons.reportng.HTMLReporter" />
    <listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
<test name="Test">
    <classes>
        <class name="com.sigma.rest.api.Test1" />
    </classes>
</test> <!-- Test -->

I hope this helps you... if issue still exists, try above options.

thanks!

酷遇一生 2024-12-11 10:25:00

检查您的项目工件(如 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文