Git Product home page Git Product logo

testng-engine's Introduction

TestNG Engine for the JUnit Platform

Allows executing TestNG tests on the JUnit Platform

Usage

Console Launcher

When running without a build tool, you need to download the following jars from Maven Central:

The following samples assume the above jars have been downloaded to the local lib folder and production and test classes to bin/main and bin/test, respectively.

$ java -cp 'lib/*' org.junit.platform.console.ConsoleLauncher \
       -cp bin/main -cp bin/test \
       --include-engine=testng --scan-classpath=bin/test

Thanks for using JUnit! Support its development at https://junit.org/sponsoring

╷
└─ TestNG ✔
   └─ CalculatorTests ✔
      ├─ add(int, int, int) ✔
      │  ├─ [0] 0, 1, 1 ✔
      │  ├─ [1] 1, 2, 3 ✔
      │  ├─ [2] 49, 51, 100 ✔
      │  └─ [3] 1, 100, 101 ✔
      └─ addsTwoNumbers ✔
            2021-07-04T17:43:52.223145 description = `1 + 1 = 2`

Test run finished after 38 ms
[         3 containers found      ]
[         0 containers skipped    ]
[         3 containers started    ]
[         0 containers aborted    ]
[         3 containers successful ]
[         0 containers failed     ]
[         5 tests found           ]
[         0 tests skipped         ]
[         5 tests started         ]
[         0 tests aborted         ]
[         5 tests successful      ]
[         0 tests failed          ]
Gradle
build.gradle[.kts]
dependencies {
    testImplementation("org.testng:testng:7.4.0")
    testRuntimeOnly("org.junit.support:testng-engine:1.0.1") // (1)
}
tasks.test {
    useJUnitPlatform() // (2)
}
  1. Add the engine as an extra dependency for running tests

  2. Configure the test task to use the JUnit Platform

Maven
pom.xml
<project>
    <!-- ... -->
    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.4.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.support</groupId>
            <artifactId>testng-engine</artifactId>
            <version>1.0.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
            </plugin>
        </plugins>
    </build>
    <!-- ... -->
</project>

Supported versions

TestNG

The engine supports TestNG version 6.14.3 and above.

JUnit Platform

The engine requires at least JUnit Platform 1.5.x.

Configuration Parameters

The following JUnit Platform configuration parameters are supported.

Execution

testng.allowReturnValues (boolean)

whether methods annotated with @Test that have return values should be considered test methods (default: false; see documentation)

testng.dataProviderThreadCount (integer)

maximum number of threads to use for running data providers in parallel, if enabled via @DataProvider(parallel = true) (default: 10; see documentation)

testng.parallel (methods|tests|classes|instances|none)

TestNG’s parallel execution mode for running tests in separate threads (default: "none"; see documentation)

testng.preserveOrder (boolean)

whether classes and methods should be run in a predictable order (default: true; see documentation)

testng.threadCount (integer)

maximum number of threads for running tests in parallel, if enabled via testng.parallel (default: 5; see documentation)

Reporting

testng.listeners (comma-separated list of fully-qualified class names)

custom listeners that should be registered when executing tests (default: ""; see documentation)

testng.outputDirectory (file path)

the output directory for reports (default: "test-output"; see documentation)

testng.useDefaultListeners (boolean)

whether TestNG’s default report generating listeners should be used (default: false; see documentation)

testng.verbose (integer)

TestNG’s level of verbosity for console output (default: 0)

Generating TestNG reports

Console Launcher
$ java -cp 'lib/*' org.junit.platform.console.ConsoleLauncher \
       -cp bin/main -cp bin/test \
       --include-engine=testng --scan-classpath=bin/test \
       --config=testng.useDefaultListeners=true \
       --config=testng.outputDirectory=test-reports
Gradle
build.gradle[.kts]
tasks.test {
    useJUnitPlatform()
    systemProperty("testng.useDefaultListeners", "true")

    val testNGReportsDir = layout.buildDirectory.dir("reports/testng")
    outputs.dir(testNGReportsDir).withPropertyName("testng-reports")
    jvmArgumentProviders += CommandLineArgumentProvider {
        listOf("-Dtestng.outputDirectory=${testNGReportsDir.get().asFile.absolutePath}")
    }
}
Maven
<project>
    <!-- ... -->
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <properties>
                        <configurationParameters>
                            testng.useDefaultListeners = true
                            testng.outputDirectory = ${project.build.directory}/testng-reports
                        </configurationParameters>
                    </properties>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <!-- ... -->
</project>

Registering custom listeners

Console Launcher
$ java -cp 'lib/*' org.junit.platform.console.ConsoleLauncher \
       -cp bin/main -cp bin/test \
       --include-engine=testng --scan-classpath=bin/test \
       --config=testng.listeners=com.acme.MyCustomListener1,com.acme.MyCustomListener2
Gradle
build.gradle[.kts]
tasks.test {
    useJUnitPlatform()
    systemProperty("testng.listeners", "com.acme.MyCustomListener1, com.acme.MyCustomListener2")
}
Maven
<project>
    <!-- ... -->
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <properties>
                        <configurationParameters>
                            testng.listeners = com.acme.MyCustomListener1, com.acme.MyCustomListener2
                        </configurationParameters>
                    </properties>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <!-- ... -->
</project>

Limitations

Groups

Groups declared via the @Test annotation on test classes and methods are exposed as tags to the JUnit Platform. Hence, you can use tag filter expressions to include or exclude certain groups. However, since tags and therefore groups are filtered rather than selected, @BeforeGroup and @AfterGroup configuration methods are not executed.

For example, given the following test class, including the tag included and excluding excluded will run test a and c but not b and d.

import org.testng.annotations.Test;

public class TestWithGroups {
    @Test(groups = "included")
    public void a() {}
    @Test(groups = {"included", "excluded"})
    public void b() {}
    @Test(groups = "included")
    public void c() {}
    @Test
    public void d() {}
}
Console Launcher
$ java -cp 'lib/*' org.junit.platform.console.ConsoleLauncher \
       -cp bin/main -cp bin/test \
       --include-engine=testng --scan-classpath=bin/test \
       --include-tag=included --exclude-tag=excluded
Gradle
build.gradle[.kts]
tasks.test {
    useJUnitPlatform {
        includeTags("included")
        excludeTags("excluded")
    }
}
Maven
<project>
    <!-- ... -->
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <groups>included</groups>
                    <excludedGroups>excluded</excludedGroups>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <!-- ... -->
</project>

Suites

The engine’s main intention is integration with build tools like Gradle and Maven. Hence, custom suites specified via testng.xml files are not supported.

testng-engine's People

Contributors

jprinet avatar marcphilipp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.