Java NoClassDefFoundError: org/testng/TestNG
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39643424/
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
NoClassDefFoundError: org/testng/TestNG
提问by Anton
This error
这个错误
NoClassDefFoundError: org/testng/TestNG
NoClassDefFoundError: org/testng/TestNG
appears when I'm trying to run my test from Testng.xml file using IntelliJ IDEA.
Running my test one by one works perfectly as well as running whole gradle project which points to testng.xml
, like grade core-test:test
当我尝试使用 IntelliJ IDEA 从 Testng.xml 文件运行我的测试时出现。一一运行我的测试完美地运行以及运行指向的整个 gradle 项目testng.xml
,例如grade core-test:test
( On my project I'm using Appium + IntelliJ + TestNG )
(在我的项目中,我使用 Appium + IntelliJ + TestNG)
But when I'm running testng.xml using IntelliJ I'm immediately getting this message after pressing Run:
但是当我使用 IntelliJ 运行 testng.xml 时,我在按下 Run 后立即收到此消息:
Exception in thread "main" java.lang.NoClassDefFoundError: org/testng/TestNG
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access0(URLClassLoader.java:73)
at java.net.URLClassLoader.run(URLClassLoader.java:368)
at java.net.URLClassLoader.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.testng.TestNG
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 18 more
采纳答案by Justin Tilson
I found a solution posted here: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206597869-Cannot-launch-NGTest-runner-in-IntelliJ-IDEA-2016-1
我在这里找到了一个解决方案:https: //intellij-support.jetbrains.com/hc/en-us/community/posts/206597869-Cannot-launch-NGTest-runner-in-IntelliJ-IDEA-2016-1
I got it to work by selecting "In whole project" (I had "In single module" selected) under the Configuration tab in the TestNG "Run/Debug Configurations."
However, the prior configuration worked in IntelliJ IDEA 15, so to me, it seems that it may have come from a breaking change with newer IDE.
我通过在TestNG“运行/调试配置”中的“配置”选项卡下选择“在整个项目中”(我选择了“在单个模块中”)来使其工作。
但是,先前的配置在 IntelliJ IDEA 15 中有效,所以对我来说,它似乎来自较新的 IDE 的重大更改。
It worked for me.
它对我有用。
回答by AP22
回答by Zeus
回答by divya
PLease follow following steps:
请按照以下步骤操作:
Add the
TestNG
library from in java build path for the project.Right click on the
project
then-> Build path -> Configure build path -> Libraries tab -> Add library -> Choose TestNG
andapply
.Create a testNG class and run the
testng.xml
file, it will work.Right click on project
-> testNG-> create testNG class -> give the details
andcreate one method
in that class then run the file.
TestNG
在项目的 java 构建路径中添加库。右键单击
project
then-> Build path -> Configure build path -> Libraries tab -> Add library -> Choose TestNG
和apply
。创建一个 testNG 类并运行该
testng.xml
文件,它将起作用。右键单击项目
-> testNG-> create testNG class -> give the details
,create one method
然后在该类中运行该文件。
回答by Dan Pearman
for me, this was a little different still. I just started using IntelliJ in 2019, and it worked fine until around Christmas. Here is what finally fixed my misbehaving system that couldn't run IntelliJ (because i could run the same files from the same repository on another system running the same IntelliJ version)
对我来说,这还是有点不同。我在 2019 年才开始使用 IntelliJ,直到圣诞节前后它都运行良好。这是最终修复了无法运行 IntelliJ 的行为不端系统的方法(因为我可以在运行相同 IntelliJ 版本的另一个系统上运行来自同一存储库的相同文件)
Had to change the template TestNG to use a Test Kind of Suite instead of Class, then set this to whole project. showing where i changed the project to Whole Project
必须更改模板 TestNG 以使用套件的测试类型而不是类,然后将其设置为整个项目。 显示我将项目更改为整个项目的位置
回答by Aditi
Follow the steps - 1. Add the TestNG library from java build path - go to project --> right-click--> properties--> java build path --> third option libraries.
按照步骤 - 1.从java构建路径添加TestNG库-转到项目-->右键单击-->属性--> java构建路径-->第三个选项库。
- TestNG - sELECT and then apply and close
- TestNG - 选择然后应用并关闭