Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

TestNG Parallel Tests in Maven: Choose Modes and Set Thread Limits

A practical guide to TestNG parallel modes, thread-count settings, shared pools in TestNG 7.9.0+, and what it takes to vary concurrency between Maven runs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To run TestNG tests in parallel through Maven, add TestNG as a test dependency, configure Maven Surefire to execute the suite, and set a parallel mode and thread limit in testng.xml. For changing the limit between runs, supply or generate the suite configuration through your build; do not assume that a Maven property automatically overrides TestNG’s thread-count in every setup.

Configure TestNG parallel execution through Maven

TestNG defines which units run concurrently and how many threads its suite may use. Maven Surefire launches the tests; the exact plugin configuration depends on the Maven, Java, TestNG, and Surefire versions in your project. TestNG’s official Maven guide shows a test-scoped dependency and directs Maven users to Surefire for test execution. Its dependency examples vary by JDK generation, so check compatibility instead of copying an example version without review.

As an Amazon Associate I earn from qualifying purchases.

  1. Add TestNG to the test classpath. Declare the TestNG dependency with test scope in your project’s Maven configuration, using a version compatible with your Java version.
  2. Configure Surefire for your project. Use the Maven Surefire Plugin to run the TestNG suite, following the plugin and TestNG versions in use. The suite XML must be included or otherwise made available to that test run.
  3. Choose a parallel boundary and thread limit. In the suite XML, select a parallel mode and set thread-count. For example, this TestNG 7.9.0-or-later configuration uses method-level parallelism:
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.1.dtd">
<suite name="Parallel suite"
       parallel="methods"
       thread-count="5"
       data-provider-thread-count="5"
       use-global-thread-pool="true">
  <test name="Application tests">
    <classes>
      <class name="example.ApplicationTest"/>
    </classes>
  </test>
</suite>

The values of 5 are illustrative, not a performance recommendation. Select limits with the test environment, shared fixtures, and external services in mind. Parallel execution can reveal unsafe shared state or place more load on constrained resources; TestNG does not make tests thread-safe merely because a parallel mode is enabled.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose what runs in parallel

“Full parallel” is not one TestNG switch. The parallel setting determines the scheduling unit, so choose it according to how tests are grouped and how much isolation they need.

Mode or setting What runs concurrently Use it when
methods Test methods Methods can safely run concurrently, including methods within the same class unless otherwise constrained.
tests TestNG <test> groups Your suite is organized into groups that can execute independently.
classes Test classes Classes are the desired concurrency boundary and their execution can overlap safely.
Separate suite files Suites, when suite-level concurrency is configured You need to run multiple suite XML files concurrently; this is distinct from parallelizing work inside one suite.

With method parallelism, TestNG’s singleThreaded behavior can keep methods from a class on the same thread. That can help preserve class-level execution constraints, but it does not replace careful management of shared state across classes, suites, or external resources. See TestNG’s parallel execution documentation for the available modes and suite behavior.

Understand the thread-count settings

TestNG distinguishes the regular test thread limit from the data-provider thread limit. The command-line options -threadcount and -dataproviderthreadcount set default maximums for parallel test execution and parallel data providers, respectively; a parallel mode must be selected for these limits to take effect. Suite XML can specify values for the corresponding settings. TestNG describes -threadcount as setting “the default maximum number of threads to use for running tests in parallel” in its command-line documentation.

When running several suite XML files, -suitethreadpoolsize controls concurrent suite execution. It is not the same as the thread limit for methods, classes, or <test> groups within one suite.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the pool scope you need

TestNG 7.9.0 introduced additional suite-level controls for sharing thread pools. These options use the testng-1.1.dtd declaration, as in the example above, and both default to false. They change how execution capacity is shared; they do not provide a mechanism for changing the numeric limit from Maven automatically.

Suite setting Pool behavior Pool size
Neither sharing option enabled Regular tests and data-provider tests use separate pools. Regular pool: thread-count; data-provider pool: data-provider-thread-count.
use-global-thread-pool="true" Regular and data-driven tests share one suite-level pool. thread-count.
share-thread-pool-for-data-providers="true" Data-provider tests share a pool with one another, but not with regular tests. data-provider-thread-count.

These pool-sharing attributes are documented for TestNG 7.9.0 and later. If you use them, confirm that your suite declaration uses the 1.1 DTD and that your TestNG version supports them. TestNG explains the behavior in Controlling ThreadPool Usage.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Change the thread limit between Maven runs

TestNG documents JVM system properties as a way to pass runtime values and says they can override parameters defined in testng.xml. Surefire can pass system properties or JVM arguments to the test process. However, those facts do not establish a universal property name that every Maven/Surefire setup automatically maps to the suite’s thread-count.

  • Use a fixed limit: Set thread-count and, if needed, data-provider-thread-count directly in testng.xml.
  • Select a limit per Maven execution: Arrange for the build to supply or generate the suite configuration for that run. Verify property interpolation and plugin behavior for the Surefire version in the project.
  • Share execution capacity: If the goal is to share workers between regular tests and data providers, use the appropriate TestNG 7.9.0-or-later pool-sharing attribute rather than treating it as a dynamic numeric override.

In short, runtime control is possible as a build-configuration pattern, but its binding must be implemented and verified for the project. Do not add a property such as threadCount and expect it to work unless your Surefire and suite configuration explicitly connect it to TestNG’s setting. See TestNG’s parameters documentation and the Maven Surefire Plugin documentation for the respective runtime and Maven configuration details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check results when enabling parallelism

  • Confirm the selected mode reflects the intended boundary: methods, <test> groups, or classes.
  • Verify the suite is actually running in the parallel mode you configured; a thread limit alone does not enable parallel execution.
  • Review tests that share mutable fixtures, files, databases, accounts, or external services. Concurrency may require isolation or resource coordination.
  • Keep regular-test and data-provider limits distinct unless a shared pool is intentional.
  • When changing the limit between Maven executions, confirm that the generated or interpolated suite contains the expected value and that the active Surefire configuration passes it to the TestNG run.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.