As mentioned in the title, I’m having issues running unit tests in Gradle using TestNG when maxParallelForks is > 1 if specifying tests in an XML file. This happens with both Gradle and Gradlew, version 1.9, 1.10 and 1.12 (I haven’t tested other versions).
It’s really a weird problem to explain with text so let’s go straight to the examples: Example code here : https://gist.github.com/FredDeschenes/4663772327926e9b0928
- Create an empty project directory - ‘gradle init --type java-library’ - Modify your build.gradle file to use TestNG (see gist) - Port ‘LibraryTest.java’ to TestNG (see gist) - Create 2 other test classes (see ‘OtherTest’ and ‘OtherOtherTest’ from gist, but any other class with @Test or a method with @Test works). - ‘gradle(w) test’ - Open ./build/reports/tests/index.html
Since only “LibraryTest.java” is declared in “testng.xml”, only this test is ran, but the output looks like this :
Now delete ‘OtherOtherTest.java’ and run ‘gradle(w) clean test’, output now looks like this :
Now delete ‘OtherTest.java’ and run ‘gradle(w) clean test’ again, output now looks like this :
Setting “scanForTestClasses = false” in build.gradle doesn’t change anything. It also doesn’t look like it’s simply a display/report error since the tests actually take more time to run.
This might also very well be a bug in TestNG, but I have no idea where to start looking for it!
Thanks for your help!
EDIT: Added image I forgot to link. EDIT2: Tested with Gradle 1.12, same issue.