简体   繁体   English

在Eclipse中测试NG测试失败,并显示错误NoClassDefFoundError:org / springframework / test / context / testng / AbstractTestNGSpringContextTests

[英]Test NG test in eclipse fails with the error NoClassDefFoundError: org/springframework/test/context/testng/AbstractTestNGSpringContextTests

 java.lang.NoClassDefFoundError: org/springframework/test/context/testng/AbstractTestNGSpringContextTests
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1012)
at java.lang.ClassLoader.loadClass(ClassLoader.java:413)
at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.testng.internal.ClassHelper.forName(ClassHelper.java:96)
at org.testng.xml.XmlClass.loadClass(XmlClass.java:78)
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:544)
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:1344)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2787)
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:643)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
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.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:103)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)

The stack trace of the exception is shown above 异常的堆栈跟踪如上所示

The test class is part of a project that makes use of maven for compilation and dependency management. 测试类是使用maven进行编译和依赖管理的项目的一部分。 I see that the 'Referenced Library' section in Eclipse contains all dependencies for the project. 我看到Eclipse中的“参考库”部分包含了项目的所有依赖关系。 The classpath entry contains spring dependencies. classpath条目包含spring依赖项。 Yet, I see this error while running the test class using Eclipse's test ng plugin. 但是,在使用Eclipse的test ng插件运行测试类时,我看到了此错误。 Please help me fix this exception! 请帮助我解决此异常! I am having a rough time fixing test ng issues in Eclipse :-( 我在解决Eclipse中的ng问题时遇到了麻烦:-(

Solutions that I have already tried and found not to be working - 我已经尝试过并发现无法使用的解决方案-

  1. Clean/Build project. 清理/构建项目。
  2. Uninstall/Reinstall testng eclipse plugin 卸载/重新安装testng eclipse插件
  3. Restart eclipse. 重新开始蚀。

I don't think figuring out the jar that the class mentioned in exception and adding the jar to classpath is the right way to fix this issue since the project that the test class is part of already has all the dependencies in place. 我不认为弄清楚jar是否异常提到了该类并将jar添加到classpath是解决此问题的正确方法,因为测试类所属的项目已经具有所有依赖项。

How do I make sure the test environment has access to all the required jars? 如何确保测试环境可以访问所有必需的jar?

Just put this to pom.xml <dependencies> section and recompile your project: 只需将其放入pom.xml <dependencies>部分,然后重新编译您的项目:

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>4.3.2.RELEASE</version>
        <scope>test</scope>
</dependency>

scope tag means it wont be compiled into the final jar/war whatever you make. scope标签意味着无论您做什么,它都不会被编译到最终的jar / war中。

I faced similar issue when i was executing new TESTNG project for very first time. 当我第一次执行新的TESTNG项目时,我遇到了类似的问题。 Solution: Its a minor thing when you create a new test NG project make sure you have added all the referenced libraries and TESTNG libriaries as well. 解决方案:在创建新的NG测试项目时,这是一件小事,请确保还添加了所有引用的库和TESTNG库。 Adding the libraries Guava 23.6 solved my issue. 添加库Guava 23.6解决了我的问题。 Do try it if you as well have performed this silly mistake. 如果您也执行了这个愚蠢的错误,请尝试一下。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.NoClassDefFoundError: org/springframework/test/context/TestContextAnnotationUtils - java.lang.NoClassDefFoundError: org/springframework/test/context/TestContextAnnotationUtils java.lang.NoClassDefFoundError: org/springframework/test/context/TestContextAnnotationUtils 在 SOAP web 服务测试 - java.lang.NoClassDefFoundError: org/springframework/test/context/TestContextAnnotationUtils in SOAP web service test Spring Test失败:java.lang.NoClassDefFoundError:org / springframework / cglib / transform / impl / MemorySafeUndeclaredThrowableStrategy - Spring Test fails: java.lang.NoClassDefFoundError: org/springframework/cglib/transform/impl/MemorySafeUndeclaredThrowableStrategy org.springframework.boot.test.mock.mockito.MockReset上的NoClassDefFoundError - NoClassDefFoundError on org.springframework.boot.test.mock.mockito.MockReset Eclipse - 调试为 - TestNG 测试:找不到测试源代码 - Eclipse - Debug as - TestNG Test: fails to find the test source code NoClassDefFoundError: org/openqa/selenium/virtualauthenticator/HasVirtualAuthenticator 在使用 TestNG 和 Maven 运行测试时出错 - NoClassDefFoundError: org/openqa/selenium/virtualauthenticator/HasVirtualAuthenticator error while running test using TestNG and Maven TestNG未在Eclipse上运行测试 - TestNG not running test on eclipse 无法解析导入org.springframework.test.context.junit4.SpringRunner - The import org.springframework.test.context.junit4.SpringRunner cannot be resolved Spring:如果无法扩展AbstractTestNGSpringContextTests,如何在Testng测试类中获取spring applicationContext - Spring: How to get spring applicationContext in a Testng test class, if I can NOT extend AbstractTestNGSpringContextTests 春季测试:为org.springframework.test.context.jdbc.Sql配置数据源 - Spring test: configure datasource for org.springframework.test.context.jdbc.Sql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM