Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError: org/testng/TestNG

Tags:

java

ide

testng

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
like image 560
Anton Avatar asked Sep 22 '16 15:09

Anton


People also ask

How do you fix No class Def Found error?

lang. NoClassDefFoundError, which means the Class Loader file responsible for dynamically loading classes can not find the . class file. So to remove this error, you should set your classpath to the location where your Class Loader is present.

Can't find or load main class in TestNG?

The "Could not find or load main class" error occurs when the JVM fails to load the main class. This can happen due to various reasons, such as: The class being declared in the incorrect package. The file path of the class not matching the fully qualified name.


2 Answers

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.

like image 60
Justin Tilson Avatar answered Sep 29 '22 04:09

Justin Tilson


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

like image 44
AP22 Avatar answered Sep 29 '22 03:09

AP22