Using TestNG Framework with Tycho

Overview

The Tycho Surefire Plug-in had support for running tests with the JUnit framework. Since version 0.26.0 Tycho supports TestNG  as test framework. If you want to use TestNG with Tycho follow these steps:

Add the TestNG p2 update site

The TestNG jar is not part of any eclipse update site (yet). So you have to add the following to your Test Plug-in pom file (or in one of its parent):

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

You might also have to add this update site to your target platform.

Add TestNG and jCommander to your Test Plug-in dependencies

Open the MANIFEST.MF file of our Test Plug-in and add the org.testng and com.beust.jcommander Plug-ins to the depenencies.

(If they could not be found, you might not have added the TestNG p2 update site URL to your target platform)

Configure Tycho to use TestNG Test Framework

If you want to use java assertions to compare acutal and expected values and depending on what your gobal compiler settings are, you might have to enable assertions with the „-ea“ (=enable assertions) commandline switch for the surefire plugin.  An example configuration could look like that one :

       <build>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-surefire-plugin</artifactId>
                <version>${tycho.version}</version>
                <configuration>
                    <argLine>-ea</argLine>
                </configuration>
            </plugin>
       </build>

Example Project

A running example Project containing one Eclipse Plug-in, one Eclipse Test Fragment and the Eclipse Plug-in that contains the TestNG stuff could be found on GitHub https://github.com/mschreiber/tychoTestNGExample/

Directory Structure and brief description:

  • bundles
    • at.mschreiber.plugin1: The Eclipse Plug-in that needs to be tested
  • releng
    • Does only contain the parent pom with all the configuration needed to run Tycho
  • tests
    • at.mschreiber.plugin1.tests : The Plug-in Fragment that contains the TestNG tests
    • pom.xml: Aggregator pom to build all the Test Fragments. This pom also contains the Tycho Surefire configuration to enable TestNG as test framework provider and the TestNG p2 update site information
  • .mvn: I do use pomless build (no pom.xml in the Plug-in and the test Plug-ins