NoClassDefFoundError: org/testng/TestNG

…衆ロ難τιáo~ 提交于 2019-12-08 15:48:04

问题


This error

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

( On my project I'm using Appium + IntelliJ + TestNG )

But when I'm running testng.xml using IntelliJ I'm immediately getting this message after pressing 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.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.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

回答1:


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

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.

It worked for me.




回答2:


adding a screenshot to aid Justin's answer above. The default is In single module which needs to be changed to In whole project.




回答3:


For me it is a little different, i was using testng configuration file to run a testng suite. I was running it from the parent module instead of the child module. The following is what I did to overcome the error




回答4:


PLease follow following steps:

  1. Add the TestNG library from in java build path for the project.

  2. Right click on the project then -> Build path -> Configure build path -> Libraries tab -> Add library -> Choose TestNG and apply.

  3. Create a testNG class and run the testng.xml file, it will work.

  4. Right click on project -> testNG-> create testNG class -> give the details and create one method in that class then run the file.



来源:https://stackoverflow.com/questions/39643424/noclassdeffounderror-org-testng-testng

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!