11

I upgraded my community edition IntelliJ from version 14 to 15.0.1 and TestNG tests which used to run in the IDE give these exceptions. How do I fix these?

Exception in thread "main" java.lang.NoClassDefFoundError: org/testng/CommandLineArgs
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:118)
    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:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: org.testng.CommandLineArgs
    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)

Let me know if more information is needed.

Ram
  • 2,237
  • 4
  • 23
  • 27
  • Sounds like a classpath issue. I'm betting that they'll run if you add TestNG to your test classpath. Not an IntelliJ problem; a project configuration problem. – duffymo Nov 25 '15 at 01:08
  • I don't believe it is an configuration issue as the same is working with Intellij14 – Ram Nov 25 '15 at 07:33
  • Note that this is on Amazon Linux. – Ram Nov 25 '15 at 07:35
  • Find this class in your testng.jar: org.testng.CommandLineArgs. Is it there? – duffymo Nov 25 '15 at 10:23
  • 1
    I'm guessing that IntelliJ 15 expects a different version of the TestNG JAR that contains the class org.testng.CommandLineArgs, but your project doesn't have it. – duffymo Nov 25 '15 at 10:37

3 Answers3

10

The org.testng.CommandLineArgs class was introduced in TestNG 6.0. I encountered the same problem and my project had TestNG 5.9. After upgrading to a newer version tests ran successfully.

Sanjiv Jivan
  • 1,922
  • 18
  • 19
  • I have Idea 2016.2 Community. Adding org.testng testng 6.8.5 test to my pom helped. – LoBo Aug 11 '16 at 09:09
0

What worked for me was adding the testng-remote dependency explicitly to my project. In my pom.xml I have these 2 dependencies:

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.14.3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.testng.testng-remote</groupId>
        <artifactId>testng-remote</artifactId>
        <version>1.4.0</version>
        <scope>test</scope>
    </dependency>

Note that testng-remote is not in the maven central repository. You need to add this repository to your pom.xml as well:

<repositories>
    <repository>
        <id>testng</id>
        <url>https://dl.bintray.com/testng-team/testng/</url>
    </repository>
</repositories>

Hope this helps someone out there.

Jeronimo Backes
  • 6,141
  • 2
  • 25
  • 29
-2

adding

<dependency>
    <groupId>com.github.adedayo.intellij.sdk</groupId>
    <artifactId>testng_rt</artifactId>
    <version>142.1</version>
</dependency>

to my pom, fix the problem.