5

When running unit tests, Gradle can execute multiple tests in parallel without any changes to the tests themselves (i.e. special annotations, test runners, etc.). I'd like to achieve the same thing with ant, but I'm not sure how.

I've seen this question but none of the answers really appeal to me. They either involve hacks with ant-contrib, special runners set up with the @RunWith annotation, some other special annotations, etc. I'm also aware of TestNG, but I can't make the Eclipse plug-in migrate our tests - and we have around 10,000 of them so I'm not doing it by hand!

Gradle doesn't need any of this stuff, so how do I do it in ant? I guess Gradle uses a special runner, but if so, it's set up as part of the JUnit setup, and not mentioned on every single test. If that's the case, then that's fine. I just don't really want to go and modify c. 10,000 unit tests!

Community
  • 1
  • 1
dty
  • 18,795
  • 6
  • 56
  • 82

1 Answers1

6

Gradle doesn't use a special JUnit runner in the strict sense of the word. It "simply" has a sophisticated test task that knows how to spin up multiple JVMs, run a subset of test classes in each of them (by invoking JUnit), and report back the results to the JVM that executes the build. There the results get aggregated to make it look like a single-JVM, single-threaded test execution. This even works for builds that define their own test listeners.

To get parallel test execution in Ant, you would need an Ant task that supports this feature (not sure if one exists). An alternative is to import your Ant build into Gradle (ant.importBuild "build.xml") and add a test task on the Gradle side.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • Hmmm, that's an interesting idea. I'm surprised that such a thing doesn't exist in Ant already, to be honest. – dty Sep 08 '11 at 20:14
  • @dty 6 years down the line, have you found a way or discovered something recently? – timekeeper Apr 23 '18 at 18:54