spring 当我做项目时,TestNG 测试用例没有编译 -> 清理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7399404/
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-09-08 04:39:08  来源:igfitidea点击:

TestNG test cases are not compiling when i do project -> clean

eclipsespringmaventestng

提问by Jon

I am using Spring, TestNG, Eclipse, Maven, Mac OS

我正在使用 Spring、TestNG、Eclipse、Maven、Mac OS

Scenario is

情景是

I am doing some changes in my test cases ( TestNG test cases ),

我正在对我的测试用例(TestNG 测试用例)进行一些更改,

Then i do Project -> Clean in eclipse

然后我做 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.

但是如果我运行 maven test ( mvn test ),整个代码都在编译,包括测试用例。

So to run the test cases i am running mvn test command only.

所以为了运行测试用例,我只运行 mvn test 命令。

Not able to run through eclipse.

无法通过日食运行。

Eclipse config:

日食配置:

Auto build on

自动构建

In Java build path the test package is included

在 Java 构建路径中,包含测试包

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)

回答by Karthikeyan

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.

看来,您没有将测试用例类包含在构建路径中。右键单击您的项目文件夹,转到项目属性-> src
通过检查它包含您的 Testcase src 文件夹。
现在它应该运行了。

回答by Jlearner

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

打开问题视图。在 Eclipse 中,转到 Window->Show View->Problems。它将在编译代码时列出所有失败。

回答by Matthew Farwell

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).

这适用于所有测试资源(包括 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.

在 Eclipse 中编辑项目属性,选择Java Build Path,然后在 Source 选项卡中,您将看到所有源目录。每个都有一个输出文件夹。这个输出文件夹需要如上。

回答by Michal

Go to Project --> Clean

Project --> Clean

That worked for me with similar problem.

这对我有类似的问题。

回答by user3464130

Please check your testNG.xmlfile for correct test because I got the same error and it was because the wrong test name was entered.

请检查您的testNG.xml文件以进行正确的测试,因为我遇到了同样的错误,这是因为输入了错误的测试名称。

回答by OverrockSTAR

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

我认为如果您的测试类在默认包和 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 -->

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

在上面,我将我的测试类从默认包移动到某个包,并如下更新了 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 hope this helps you... if issue still exists, try above options.

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

thanks!

谢谢!

回答by Prasanth RJ

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 )

检查您的项目工件(如 excel、属性文件、xml 文件等)是否在文本编辑器等中打开(如果是,请关闭它们并重建)

When you clean and rebuild make sure all project dependent files are closed and you do build.

当您清理和重建时,请确保关闭所有项目相关文件并进行构建。

回答by Ross

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

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

回答by chank

I solved this by:

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

  1. Changing the build path / deleting some of the wrong ones
  2. Cleaning the project
  1. 更改构建路径/删除一些错误的路径
  2. 清理项目