How/why do tests run so fast


(Jordan Zimmerman) #1

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.


(Peter Niederwieser) #2

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


(Jordan Zimmerman) #3

There’s nothing specifically setting parallel


(Luke Daley) #4

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


(Jordan Zimmerman) #5

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.


(Jordan Zimmerman) #6

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

tasks.test.useTestNG()

Man - Gradle feels as obtuse as Maven sometimes.


(Luke Daley) #7

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


(Jordan Zimmerman) #8

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


(Justin Ryan) #9

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.


(Luke Daley) #10

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.


(Jordan Zimmerman) #11

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


(Peter Niederwieser) #12

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.


(Jordan Zimmerman) #13

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.


(Peter Niederwieser) #14

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.


(Eric Wendelin) #15

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


(Peter Niederwieser) #16

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