# How/why do tests run so fast

**URL:** <https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529>\
**Category:** Old Forum Archive\
**Created:** [March 24, 2012, 8:02am UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529 "2012-03-24T08:02:00Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![JordanZimmerman](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jordanzimmerman/32/193_2.png) [@JordanZimmerman](https://discuss.gradle.org/u/JordanZimmerman)\
**Post date:** [March 24, 2012, 8:02am UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/1 "2012-03-24T08:02:00Z")

</div>

I notice that tests run orders of magnitude faster than under Maven or in my IDE. What’s the explanation for this? FYI - I’m using TestNG.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [March 25, 2012, 3:14am UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/2 "2012-03-25T03:14:00Z")

</div>

Do you run tests in parallel with Gradle (‘test.maxParallelForks=n’), or does your Gradle build configure TestNG to run them in parallel?

---

<div class="post-metadata">

**Author:** ![JordanZimmerman](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jordanzimmerman/32/193_2.png) [@JordanZimmerman](https://discuss.gradle.org/u/JordanZimmerman)\
**Post date:** [March 25, 2012, 3:45am UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/3 "2012-03-25T03:45:00Z")

</div>

There’s nothing specifically setting parallel

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [March 26, 2012, 9:18am UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/4 "2012-03-26T09:18:00Z")

</div>

I’d be very suspicious about this. You might want to check that all of your tests are indeed running.

---

<div class="post-metadata">

**Author:** ![JordanZimmerman](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jordanzimmerman/32/193_2.png) [@JordanZimmerman](https://discuss.gradle.org/u/JordanZimmerman)\
**Post date:** [March 26, 2012, 8:11pm UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/5 "2012-03-26T20:11:00Z")

</div>

I’m beginning to think that the tests are not running. The test report is empty. I’m using testng on a multi-project build. Are there known bugs with this setup? gradle clean test doesn’t seem to be working.

---

<div class="post-metadata">

**Author:** ![JordanZimmerman](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jordanzimmerman/32/193_2.png) [@JordanZimmerman](https://discuss.gradle.org/u/JordanZimmerman)\
**Post date:** [March 26, 2012, 8:17pm UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/6 "2012-03-26T20:17:00Z")

</div>

After some research, it appears I have to add this?

```gradle
tasks.test.useTestNG()

```

Man - Gradle feels as obtuse as Maven sometimes.

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [March 26, 2012, 8:30pm UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/7 "2012-03-26T20:30:00Z")

</div>

Yes, you have to inform Gradle that you are using TestNG.

---

<div class="post-metadata">

**Author:** ![JordanZimmerman](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jordanzimmerman/32/193_2.png) [@JordanZimmerman](https://discuss.gradle.org/u/JordanZimmerman)\
**Post date:** [March 26, 2012, 8:38pm UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/8 "2012-03-26T20:38:00Z")

</div>

Can’t Gradle infer that from the code? I don’t have to do this with Maven.

---

<div class="post-metadata">

**Author:** ![quidryan](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/quidryan/32/73_2.png) [@quidryan](https://discuss.gradle.org/u/quidryan)\
**Post date:** [March 27, 2012, 3:00am UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/9 "2012-03-27T03:00:00Z")

</div>

The documentation explicitly states that Gradle will figure it out, 23.12.3. Test detection. Likewise, it could look at the testCompile configuration to figure it out, if not the source. It might be a bug in the detection code.

This specific project has junit annotations in one submodule, in TestMapsWithJersey.java and TestStringsWithJersey.java, TestStringsWithRestEasy.java. Everything else is TestNG.

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [March 27, 2012, 11:46am UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/10 "2012-03-27T11:46:00Z")

</div>

That documentation is poorly worded.

What it’s trying to say is that once you tell Gradle what the test framework is, it will scan and find the potential test classes for you so you don’t have to manually construct a suite.

---

<div class="post-metadata">

**Author:** ![JordanZimmerman](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jordanzimmerman/32/193_2.png) [@JordanZimmerman](https://discuss.gradle.org/u/JordanZimmerman)\
**Post date:** [March 27, 2012, 10:34pm UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/11 "2012-03-27T22:34:00Z")

</div>

Can explain the decision on this? IMO Gradle, at minimum, should be as convenient as Maven.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [March 28, 2012, 8:56am UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/12 "2012-03-28T08:56:00Z")

</div>

It would have to do more scanning work (something which Maven doesn’t do at all), and if it found both JUnit and TestNG tests, it would have to ask you for a decision anyway (because it can’t run both in one task). In the future, we might split up JUnit and TestNG into two separate tasks.

---

<div class="post-metadata">

**Author:** ![JordanZimmerman](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jordanzimmerman/32/193_2.png) [@JordanZimmerman](https://discuss.gradle.org/u/JordanZimmerman)\
**Post date:** [March 28, 2012, 7:53pm UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/13 "2012-03-28T19:53:00Z")

</div>

The combination of JUnit and TestNG is a mistake (caused by auto-import with my IDE). It doesn’t make much sense for Gradle to default to using JUnit. It seems arbitrary. It came as a big surprise to me. Software should help us where it can and Gradle can easily detect with test framework to use.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [March 29, 2012, 12:46am UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/14 "2012-03-29T00:46:00Z")

</div>

It’s not completely arbitrary in the sense that JUnit is much more widely used than TestNG. I agree that there are better solutions, but that’s what we have today. I invite you to get involved and help move things forward.

---

<div class="post-metadata">

**Author:** ![eriwen](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/eriwen/32/4786_2.png) [@eriwen](https://discuss.gradle.org/u/eriwen)\
**Post date:** [March 30, 2012, 10:59pm UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/15 "2012-03-30T22:59:00Z")

</div>

Do you happen to have a reference of all these magical Gradle flags available?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [March 31, 2012, 12:25am UTC](https://discuss.gradle.org/t/how-why-do-tests-run-so-fast/7529/16 "2012-03-31T00:25:00Z")

</div>

What’s magical about them? They are documented in the DSL reference and Javadoc.
