Eclipse - Install TestNG plugin

By xngo on June 11, 2019


TestNG is a testing framework that is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc...

Install TestNG plugin

  1. Navigate to Help > Eclipse Marketplace....
  2. Search TestNG and follow the instructions.
  3. You also need to add Jcommander JAR file to your library class path. Otherwise, when you run TestNG, it will show the following error message:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(
    at java.lang.Class.privateGetMethodRecursive(
    at java.lang.Class.getMethod0(
    at java.lang.Class.getMethod(
    at sun.launcher.LauncherHelper.validateMainClass(
    at sun.launcher.LauncherHelper.checkAndLoadMain(
Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    ... 7 more

Here is a video showing how to install TestNG plugin in Eclipse.

Install TestNG plugin in Eclipse

Sample codes

import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
public class TestngHelloWorld {
    @Test(description = "AssertTrue: Test positive.")
    public void testAssertTruePositive() {
        assertTrue(true, "Positive assertTrue().");
    @Test(description = "AssertFalse: Test negative.")
    public void testAssertFalseNegative() {
        assertFalse(true, "This will fail.");
    @Test(description = "AssertEquals: Test negative.")
    public void testAssertEqualsNegative() {
        String actual = "Some very long string.";
        String expected = "some string";
        String message = "Error message to display if failed.";
        assertEquals(actual, expected, message);

Output results of the code above





About the author

Xuan Ngo is the founder of He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.