Gradle & TestNG Parallel Data Provider Thread Count Issue

Too Many Test Threads

I use TestNG and Gradle for some of the Selenium automation projects I work with. We’ve run tests in parallel using -Dthreadcount=10 and have recently created some data driven tests using TestNG’s @DataProvider.

However when using @DataProvider(parallel = true) we were seeing 20 tests being executed at the same time not just 10! As it turns out, TestNG has a separate thread pool for data providers, with a default of 10 threads - thus causing the unexpected behaviour.

Solution

To solve this you can add -Ddataproviderthreadcount=1 to the JVM command line or specify it in the testNG part of the Gradle file. This also works for IntelliJ when running TestNG tests, add -Ddataproviderthreadcount=1 to the VM Arguments section.