How to enable TestNG launch configurations in Eclipse IDE (Windows)

When using TestNG 5.11 (and at least one earlier version, 5.9) with the Eclipse IDE 3.4.2 (Ganymede, for Windows), one can’t setup a Run configuration for TestNG in the usual way. That is, one can’t use Project | Properties | Run/Debug because only Java App and Java Applet options are presented there. (Of course, one has to install the TestNG plugin first for this to make any sense.) Instead, here’s a workaround gleaned from a post by Ajay Mehra:

  1. Make sure you haven’t hidden any launch configuration types
    1. Go to the top menu bar and select Window | Preferences.
    2. In the left pane, select Run/Debug | Launching | Launch Configurations. On the right side, make sure that Java Application and TestNG are shown and not checked. (You may have to check ‘Filter checked launch types’ temporarily in order to scroll or uncheck some items.)
  2. Make sure the class(es) you want to test have @Test annotations in them
    1. If you want to see an example, look at the SimpleTest class definition near the top of the TestNG homepage.
    2. Note that in SimpleTest, it’s not necessary to include an @BeforeClass annotation anywhere, nor is it necessary to include “(groups …)” after the @Test annotations. And rather than importing all of “org.testng.annotations.*”, you may be able to get away with just importing “org.testng.annotations.Test”.
    3. To support the @Test annotation, the IDE will want to add the testng-jdkNN.jar (where NN is 15 if you’re using JDK 1.5) to your project’s classpath.
    4. Any methods you want to be used as tests should be marked as public, so TestNG can invoke them.
      • If you don’t make any test methods public, then when you run your tests, the TestNG tab near the console tab will show that zero tests were run.
  3. Create a launch configuration for your test
    1. Go to the top menu bar and click the down-facing black triangle to the right of the Run button (a green circle with a white triangle in it). This should trigger a dropdown menu that includes “Run Configurations…” Select it.
    2. Select TestNG in the left pane, then click the New button in the upper left (the white rectangle with a yellow plus in the upper right). Enter a name for the new launch config; if your test will use just one class of test methods, that class name would probably be a good choice as a memory aid.
    3. Under the Test tab, browse to the “Project” of the test, and then select a “Run…” target. (For example, if you’re trying things out with SimpleTest, you should have created a new empty project, pasted SimpleTest.java into it, and now use the Browse button for Class to select SimpleTest.java.)
    4. If you need to provide any arguments to the JVM before the test is launched, do so under the Arguments tab.
    5. To save your edits, click Apply. When you’re done editing, click Close (or you could execute the test by clicking Run).
  4. Verify that the test is setup correctly
    1. Run the test by selecting the black triangle again near the green Run button, and then selecting the launch config you just named.
    2. The Console tab should show
      [Parser] Running:
        pathToYourProjectProjFoldertemp-testng-customsuite.xml

      The name of the xml file shown here is what TestNG generates if your launch config doesn’t use the “Suite” option and you didn’t provide your own xml file.

      Following that will be any System.out printing your test methods did, plus

      PASSED: testMethodName

      for any of your test methods that passed.

      Finally, there will be a summary report like this

      ===============================================
          SimpleTest
          Tests run: 2, Failures: 0, Skips: 0
      ===============================================
    3. A similar, more graphical view of the summary report should be available under the TestNG tab.
    4. If the report says “Tests run: 0”, double-check that your @Test annotations are on the right methods, and that those methods are public.
Print Friendly, PDF & Email