Class TestNgOperation


public class TestNgOperation extends TestOperation<TestNgOperation,List<String>>
Run tests with TestNG.
Since:
1.0
Author:
Erik C. Thauvin
  • Constructor Details

    • TestNgOperation

      public TestNgOperation()
  • Method Details

    • alwaysRunListeners

      public TestNgOperation alwaysRunListeners(Boolean isAlwaysRunListeners)
      Should Method Invocation Listeners be run even for skipped methods.

      Default is true

      Parameters:
      isAlwaysRunListeners - true or false
      Returns:
      this operation instance
    • dataProviderThreadCount

      public TestNgOperation dataProviderThreadCount(int count)
      This sets the default maximum number of threads to use for data providers when running tests in parallel. It will only take effect if the parallel mode has been selected (for example,with the parallel option). This can be overridden in the suite definition.
      Parameters:
      count - the count
      Returns:
      this operation instance
    • dependencyInjectorFactory

      public TestNgOperation dependencyInjectorFactory(String injectorFactory)
      The dependency injector factory implementation that TestNG should use.
      Parameters:
      injectorFactory - the injector factory
      Returns:
      this operation instance
    • directory

      public TestNgOperation directory(String directoryPath)
      The directory where the reports will be generated

      Default is build/test-output)

      Parameters:
      directoryPath - the directory path
      Returns:
      this operation instance
    • directory

      public TestNgOperation directory(File directoryPath)
      The directory where the reports will be generated

      Default is build/test-output)

      Parameters:
      directoryPath - the directory path
      Returns:
      this operation instance
    • directory

      public TestNgOperation directory(Path directoryPath)
      The directory where the reports will be generated

      Default is build/test-output)

      Parameters:
      directoryPath - the directory path
      Returns:
      this operation instance
    • excludeGroups

      public TestNgOperation excludeGroups(String... group)
      The list of groups you want to be excluded from this run.
      Parameters:
      group - one or more groups
      Returns:
      this operation instance
      See Also:
    • excludeGroups

      public TestNgOperation excludeGroups(Collection<String> group)
      The list of groups you want to be excluded from this run.
      Parameters:
      group - the list of groups
      Returns:
      this operation instance
      See Also:
    • execute

      public void execute() throws IOException, InterruptedException, ExitStatusException
      Overrides:
      execute in class AbstractProcessOperation<TestNgOperation>
      Throws:
      IOException
      InterruptedException
      ExitStatusException
    • executeConstructProcessCommandList

      protected List<String> executeConstructProcessCommandList()
      Part of the execute operation, constructs the command list to use for building the process.
      Overrides:
      executeConstructProcessCommandList in class TestOperation<TestNgOperation,List<String>>
      Returns:
      the command list
    • fromProject

      public TestNgOperation fromProject(BaseProject project)
      Configures the BaseProject.
      Overrides:
      fromProject in class TestOperation<TestNgOperation,List<String>>
      Parameters:
      project - the project
      Returns:
      this operation instance
    • failWhenEverythingSkipped

      public TestNgOperation failWhenEverythingSkipped(Boolean isFailAllSkipped)
      Should TestNG fail execution if all tests were skipped and nothing was run.
      Parameters:
      isFailAllSkipped - true or false
      Returns:
      this operation instance
    • failurePolicy

      public TestNgOperation failurePolicy(TestNgOperation.FailurePolicy policy)
      Whether TestNG should continue to execute the remaining tests in the suite or skip them if in a @Before* method.
      Parameters:
      policy - the policy
      Returns:
      this operation instance
    • generateResultsPerSuite

      public TestNgOperation generateResultsPerSuite(Boolean resultsPerSuite)
      Should TestNG generate results on a per-suite basis by creating a subdirectory for each suite and dumping results into it.

      Default is false

      .
      Parameters:
      resultsPerSuite - true or false
      Returns:
      this operation instance
    • groups

      public TestNgOperation groups(String... group)
      The list of groups you want to run.

      For example: "windows", "linux", "regression

      Parameters:
      group - one or more groups
      Returns:
      this operation instance
      See Also:
    • groups

      public TestNgOperation groups(Collection<String> group)
      The list of groups you want to run.

      For example: "windows", "linux", "regression

      Parameters:
      group - the list of groups
      Returns:
      this operation instance
      See Also:
    • ignoreMissedTestName

      public TestNgOperation ignoreMissedTestName(Boolean isIgnoreMissedTestNames)
      Ignore missed test names given by testNames and continue to run existing tests, if any.

      Default is false

      Parameters:
      isIgnoreMissedTestNames - true or false
      Returns:
      this operation instance
    • includeAllDataDrivenTestsWhenSkipping

      public TestNgOperation includeAllDataDrivenTestsWhenSkipping(Boolean isIncludeDrivenTestsWhenSkipping)
      Should TestNG report all iterations of a data driven test as individual skips, in-case of upstream failures.

      Default is false

      Parameters:
      isIncludeDrivenTestsWhenSkipping - true or false
      Returns:
      this operation instance
    • jUnit

      public TestNgOperation jUnit(Boolean isJunit)
      Enables or disables the JUnit mode.

      Default is false

      Parameters:
      isJunit - true or false
      Returns:
      this operation instance
    • listener

      public TestNgOperation listener(String... listener)
      The list of .class files or list of class names implementing ITestListener or ISuiteListener
      Parameters:
      listener - one or more listeners
      Returns:
      this operation instance
      See Also:
    • listener

      public TestNgOperation listener(Collection<String> listener)
      The list of .class files or list of class names implementing ITestListener or ISuiteListener
      Parameters:
      listener - the list of listeners
      Returns:
      this operation instance
      See Also:
    • listenerComparator

      public TestNgOperation listenerComparator(String listenerComparator)
      An implementation of ListenerComparator that will be used by TestNG to determine order of execution for listeners.
      Parameters:
      listenerComparator - the listener comparator
      Returns:
      this operation instance
    • listenerFactory

      public TestNgOperation listenerFactory(String listenerFactory)
      The factory used to create TestNG listeners.
      Parameters:
      listenerFactory - the listener factory
      Returns:
      this operation instance
    • log

      public TestNgOperation log(int level)
      Set the Level of verbosity.
      Parameters:
      level - the level
      Returns:
      this operation instance
      See Also:
    • methodSelectors

      public TestNgOperation methodSelectors(String... selector)
      Specifies the list of .class files or class names implementing IMethodSelector.

      For example: "com.example.Selector1:3", "com.example.Selector2:2"

      Parameters:
      selector - one or more selectors
      Returns:
      this operation instance
      See Also:
    • methodSelectors

      public TestNgOperation methodSelectors(Collection<String> selector)
      Specifies the list of .class files or class names implementing IMethodSelector.

      For example: "com.example.Selector1:3", "com.example.Selector2:2"

      Parameters:
      selector - the list of selectors
      Returns:
      this operation instance
      See Also:
    • methods

      public TestNgOperation methods(String... method)
      Lets you specify individual methods to run.

      For example: "com.example.Foo.f1", "com.example.Bar.f2"

      Parameters:
      method - one or more methods
      Returns:
      this operation instance
      See Also:
    • methods

      public TestNgOperation methods(Collection<String> method)
      Lets you specify individual methods to run.

      For example: "com.example.Foo.f1", "com.example.Bar.f2"

      Parameters:
      method - the list of methods
      Returns:
      this operation instance
      See Also:
    • methods

      public Set<String> methods()
      Returns the methods to run.
      Returns:
      the set of methods
    • mixed

      public TestNgOperation mixed(Boolean isMixed)
      Mixed mode autodetects the type of current test and run it with appropriate runner.

      Default is false

      Parameters:
      isMixed - true or false
      Returns:
      this operation instance
    • objectFactory

      public TestNgOperation objectFactory(String... factory)
      The list of .class files or class names implementing ITestRunnerFactory.

      A fully qualified class name that implements org.testng.ITestObjectFactory which can be used to create test class and listener instances.

      Parameters:
      factory - one or more factory
      Returns:
      this operation instance
      See Also:
    • objectFactory

      public TestNgOperation objectFactory(Collection<String> factory)
      The list of .class files or class names implementing ITestRunnerFactory.

      A fully qualified class name that implements org.testng.ITestObjectFactory which can be used to create test class and listener instances.

      Parameters:
      factory - the list of factories
      Returns:
      this operation instance
      See Also:
    • options

      public Map<String,String> options()
      Returns the run options.
      Returns:
      the map of run options
    • overrideIncludedMethods

      public TestNgOperation overrideIncludedMethods(String... method)
      The list of fully qualified class names of listeners that should be skipped from being wired in via Service Loaders.
      Parameters:
      method - one or more methods
      Returns:
      this operation instance
      See Also:
    • overrideIncludedMethods

      public TestNgOperation overrideIncludedMethods(Collection<String> method)
      The list of fully qualified class names of listeners that should be skipped from being wired in via Service Loaders.
      Parameters:
      method - the list of methods
      Returns:
      this operation instance
      See Also:
    • packages

      public TestNgOperation packages(String... name)
      The list of packages to include in this test. If the package name ends with .* then subpackages are included too. Required if no suites(String...suites) specified.

      For example: "com.example", "test.sample.*"

      Parameters:
      name - one or more names
      Returns:
      this operation instance
      See Also:
    • packages

      public TestNgOperation packages(Collection<String> name)
      The list of packages to include in this test. If the package name ends with .* then subpackages are included too. Required if no suites(String...suites) specified.

      For example: "com.example", "test.sample.*"

      Parameters:
      name - the list of names
      Returns:
      this operation instance
      See Also:
    • packages

      public Set<String> packages()
      Returns the suite packages to run.
      Returns:
      the set of packages
    • parallel

      public TestNgOperation parallel(TestNgOperation.Parallel mechanism)
      If specified, sets the default mechanism used to determine how to use parallel threads when running tests. If not set, default mechanism is not to use parallel threads at all. This can be overridden in the suite definition.
      Parameters:
      mechanism - the mechanism
      Returns:
      this operation instance
      See Also:
    • port

      public TestNgOperation port(int port)
      Specifies the port number.
      Parameters:
      port - the port
      Returns:
      this operation instance
    • propagateDataProviderFailureAsTestFailure

      public TestNgOperation propagateDataProviderFailureAsTestFailure(Boolean isPropagateDataProviderFailure)
      Should TestNG consider failures in Data Providers as test failures.

      Default is false

      Parameters:
      isPropagateDataProviderFailure - true or false
      Returns:
      this operation instance
    • reporter

      public TestNgOperation reporter(String reporter)
      Specifies the extended configuration for custom report listener.
      Parameters:
      reporter - the reporter
      Returns:
      this operation instance
    • shareThreadPoolForDataProviders

      public TestNgOperation shareThreadPoolForDataProviders(boolean shareThreadPoolForDataProviders)
      Should TestNG use a global Shared ThreadPool (At suite level) for running data providers.
      Parameters:
      shareThreadPoolForDataProviders - true or false
      Returns:
      this operation instance
    • sourceDir

      public TestNgOperation sourceDir(String... directory)
      The directories where your javadoc annotated test sources are. This option is only necessary if you are using javadoc type annotations. (e.g. "src/test" or "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng").
      Parameters:
      directory - one or more directories
      Returns:
      this operation instance
      See Also:
    • sourceDir

      public TestNgOperation sourceDir(File... directory)
      The directories where your javadoc annotated test sources are. This option is only necessary if you are using javadoc type annotations. (e.g. "src/test" or "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng").
      Parameters:
      directory - one or more directories
      Returns:
      this operation instance
      See Also:
    • sourceDir

      public TestNgOperation sourceDir(Path... directory)
      The directories where your javadoc annotated test sources are. This option is only necessary if you are using javadoc type annotations. (e.g. "src/test" or "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng").
      Parameters:
      directory - one or more directories
      Returns:
      this operation instance
      See Also:
    • sourceDir

      public TestNgOperation sourceDir(Collection<String> directory)
      The directories where your javadoc annotated test sources are. This option is only necessary if you are using javadoc type annotations. (e.g. "src/test" or "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng").
      Parameters:
      directory - the list of directories
      Returns:
      this operation instance
      See Also:
    • sourceDirFiles

      public TestNgOperation sourceDirFiles(Collection<File> directory)
      The directories where your javadoc annotated test sources are. This option is only necessary if you are using javadoc type annotations. (e.g. "src/test" or "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng").
      Parameters:
      directory - the list of directories
      Returns:
      this operation instance
      See Also:
    • sourceDirPaths

      public TestNgOperation sourceDirPaths(Collection<Path> directory)
      The directories where your javadoc annotated test sources are. This option is only necessary if you are using javadoc type annotations. (e.g. "src/test" or "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng").
      Parameters:
      directory - the list of directories
      Returns:
      this operation instance
      See Also:
    • spiListenersToSkip

      public TestNgOperation spiListenersToSkip(String... listenerToSkip)
      Specifies the List of fully qualified class names of listeners that should be skipped from being wired in via Service Loaders.
      Parameters:
      listenerToSkip - the listeners to skip
      Returns:
      this operation instance
      See Also:
    • spiListenersToSkip

      public TestNgOperation spiListenersToSkip(Collection<String> listenerToSkip)
      Specifies the List of fully qualified class names of listeners that should be skipped from being wired in via Service Loaders.
      Parameters:
      listenerToSkip - the listeners to skip
      Returns:
      this operation instance
      See Also:
    • suiteName

      public TestNgOperation suiteName(String name)
      This specifies the default name of the test suite, if not specified in the suite definition file or source code. This option is ignored if the suite.xml file or the source code specifies a different suite name.
      Parameters:
      name - the name
      Returns:
      this operation instance
    • suiteThreadPoolSize

      public TestNgOperation suiteThreadPoolSize(int poolSize)
      Specifies the size of the thread pool to use to run suites. Required if no packages(String...) specified.
      Parameters:
      poolSize - the pool size
      Returns:
      this operation instance
    • suites

      public TestNgOperation suites(String... suite)
      Specifies the suites to run.

      For example: "testng.xml", "testng2.xml"

      Parameters:
      suite - one or more suites
      Returns:
      this operation instance
      See Also:
    • suites

      public TestNgOperation suites(Collection<String> suite)
      Specifies the suites to run.

      For example: "testng.xml", "testng2.xml"

      Parameters:
      suite - the list of suites
      Returns:
      this operation instance
      See Also:
    • suites

      public Set<String> suites()
      Returns the suites to run.
      Returns:
      the set of suites
    • testClass

      public TestNgOperation testClass(String... aClass)
      Specifies the list of class files.

      For example: "org.foo.Test1","org.foo.test2"

      Parameters:
      aClass - one or more classes
      Returns:
      this operation instance
      See Also:
    • testClass

      public TestNgOperation testClass(Collection<String> aClass)
      Specifies the list of class files.

      For example: "org.foo.Test1","org.foo.test2"

      Parameters:
      aClass - the list of classes
      Returns:
      this operation instance
      See Also:
    • testClasspath

      public TestNgOperation testClasspath(String... entry)
      Specifies the classpath entries used to run tests.
      Parameters:
      entry - one or more entries
      Returns:
      this operation instance
      See Also:
    • testClasspath

      public TestNgOperation testClasspath(Collection<String> entry)
      Specifies the classpath entries used to run tests.
      Parameters:
      entry - the list of entries
      Returns:
      this operation instance
      See Also:
    • testClasspath

      public Set<String> testClasspath()
      Returns the classpath entries used for running tests.
      Returns:
      the set of test classpath
    • testJar

      public TestNgOperation testJar(String jar)
      Specifies a jar file that contains test classes. If a testng.xml file is found at the root of that jar file, it will be used, otherwise, all the test classes found in this jar file will be considered test classes.
      Parameters:
      jar - the jar
      Returns:
      this operation instance
    • testName

      public TestNgOperation testName(String name)
      This specifies the default name of test, if not specified in the suite definition file or source code. This option is ignored if the suite.xml file or the source code specifies a different test name.
      Parameters:
      name - the name
      Returns:
      this operation instance
    • testNames

      public TestNgOperation testNames(String... name)
      Only tests defined in a <test> tag matching one of these names will be run.
      Parameters:
      name - one or more names
      Returns:
      this operation instance
      See Also:
    • testNames

      public TestNgOperation testNames(Collection<String> name)
      Only tests defined in a <test> tag matching one of these names will be run.
      Parameters:
      name - the list of names
      Returns:
      this operation instance
      See Also:
    • testRunFactory

      public TestNgOperation testRunFactory(String factory)
      Specifies the factory used to create tests.
      Parameters:
      factory - the factory
      Returns:
      this operation instance
    • threadCount

      public TestNgOperation threadCount(int count)
      This sets the default maximum number of threads to use for running tests in parallel. It will only take effect if the parallel mode has been selected (for example, with the parallel option). This can be overridden in the suite definition.
      Parameters:
      count - the count
      Returns:
      this operation instance
    • threadPoolFactoryClass

      public TestNgOperation threadPoolFactoryClass(String factoryClass)
      Specifies the thread pool executor factory implementation that TestNG should use.
      Parameters:
      factoryClass - the factory class
      Returns:
      this operation instance
    • useDefaultListeners

      public TestNgOperation useDefaultListeners(Boolean isDefaultListener)
      Whether to use the default listeners

      Default is true

      Parameters:
      isDefaultListener - true or false
      Returns:
      this operation instance
    • useGlobalThreadPool

      public TestNgOperation useGlobalThreadPool(boolean useGlobalThreadPool)
      Should TestNG use a global Shared ThreadPool (At suite level) for running regular and data driven tests.
      Parameters:
      useGlobalThreadPool - true or false
      Returns:
      this operation instance
    • verbose

      public TestNgOperation verbose(int level)
      Set the Level of verbosity.
      Parameters:
      level - the level
      Returns:
      this operation instance
      See Also:
    • xmlPathInJar

      public TestNgOperation xmlPathInJar(String path)
      This attribute should contain the path to a valid XML file inside the test jar (e.g. "resources/testng.xml"). The default is testng.xml, which means a file called testng.xml at the root of the jar file. This option will be ignored unless a test jar is specified.
      Parameters:
      path - the path
      Returns:
      this operation instance
    • xmlPathInJar

      public TestNgOperation xmlPathInJar(File path)
      This attribute should contain the path to a valid XML file inside the test jar (e.g. "resources/testng.xml"). The default is testng.xml, which means a file called testng.xml at the root of the jar file. This option will be ignored unless a test jar is specified.
      Parameters:
      path - the path
      Returns:
      this operation instance
    • xmlPathInJar

      public TestNgOperation xmlPathInJar(Path path)
      This attribute should contain the path to a valid XML file inside the test jar (e.g. "resources/testng.xml"). The default is testng.xml, which means a file called testng.xml at the root of the jar file. This option will be ignored unless a test jar is specified.
      Parameters:
      path - the path
      Returns:
      this operation instance