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.
- 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.
- 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.
- 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.
Recommended Free Tools
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.
#1 Best Overall
| 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.
Rank #2
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.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →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.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.
Rank #4
- Use a fixed limit: Set
thread-countand, if needed,data-provider-thread-countdirectly intestng.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.
Quick Recap
Best Value
- Used Book in Good Condition
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.




