Class TestNGTestEngine

java.lang.Object
org.junit.support.testng.engine.TestNGTestEngine
All Implemented Interfaces:
org.junit.platform.engine.TestEngine

public class TestNGTestEngine extends Object implements org.junit.platform.engine.TestEngine
The TestNG TestEngine for running TestNG tests on the JUnit Platform.
Since:
1.0
  • Field Details

    • DISCOVERY_REQUEST_RESOLVER

      private static final org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver<TestNGEngineDescriptor> DISCOVERY_REQUEST_RESOLVER
  • Constructor Details

    • TestNGTestEngine

      public TestNGTestEngine()
      Create a new instance (typically called by the JUnit Platform via ServiceLoader).
  • Method Details

    • getId

      public String getId()
      Specified by:
      getId in interface org.junit.platform.engine.TestEngine
    • discover

      public org.junit.platform.engine.TestDescriptor discover(org.junit.platform.engine.EngineDiscoveryRequest request, org.junit.platform.engine.UniqueId uniqueId)
      Discover TestNG tests based on the supplied request.

      Supports the following selectors:

      • ClasspathRootSelector
      • ClassSelector
      • MethodSelector
      • ModuleSelector
      • PackageSelector
      • UniqueIdSelector

      Custom test suites specified via testng.xml files are not supported.

      Supports the following filters:

      • ClassNameFilter
      • PackageNameFilter
      • Any post-discovery filter, e.g. for included/excluded tags

      The implementation collects a list of potential test classes and method names and uses TestNG's dry-run mode to determine which of them are TestNG test classes and methods. Since TestNG can only run either classes or methods, it will be executed twice in the edge case that class and method selectors are part of the discovery request.

      Specified by:
      discover in interface org.junit.platform.engine.TestEngine
    • execute

      public void execute(org.junit.platform.engine.ExecutionRequest request)
      Execute the previously discovered TestNG tests in the supplied request.

      Supports the following configuration parameters:

      Execution

      testng.allowReturnValues (file path)
      whether methods annotated with @Test that have return values should be considered test methods (default: false)
      testng.dataProviderThreadCount (file path)
      maximum number of threads to use for running data providers in parallel, if enabled via DataProvider.parallel() (default: 10)
      testng.parallel (methods|tests|classes|instances|none)
      TestNG's parallel execution mode for running tests in separate threads (default: "none")
      testng.preserveOrder (boolean)
      whether classes and methods should be run in a predictable order (default: true)
      testng.threadCount (boolean)
      maximum number of threads for running tests in parallel, if enabled via testng.parallel (default: 5)

      Reporting

      testng.listeners (comma-separated list of fully-qualified class names)
      custom listeners that should be registered when executing tests (default: "")
      testng.outputDirectory (file path)
      the output directory for reports (default: "test-output")
      testng.useDefaultListeners (boolean)
      whether TestNG's default report generating listeners should be used (default: false)
      testng.verbose (integer)
      TestNG's level of verbosity (default: 0)

      The implementation configures TestNG as if the discovered methods were specified on the command line.

      Data providers test methods are reported as a nested structure, i.e. individual invocations are reported underneath the test methods along with their parameters:

      
       └─ TestNG ✔
          └─ DataProviderMethodTestCase ✔
             └─ test(java.lang.String) ✔
                ├─ [0] a ✔
                └─ [1] b ✔
       
      Specified by:
      execute in interface org.junit.platform.engine.TestEngine
    • configureAndRun

      private static void configureAndRun(org.junit.platform.engine.ConfigurationParameters configurationParameters, org.testng.ITestNGListener listener, TestNGTestEngine.Configurer... configurers)
    • withTemporarySystemProperty

      private static void withTemporarySystemProperty(String key, String value, Runnable action)