Jae Carr
Jae Carr

Reputation: 1225

Gradle Test, run verbosely?

We have a task in our Gradle build file called integration which extends Test and is used to run all of our integration tests. Our integration tests take quite some time to run because we have, as you might expect, quite a few. And several of them can run for up to 10 minutes because of some lengthy DB interactions.

Right now all I can see when they are running is >Building > :integration. And it sits at that point for...a very long time. I'm often not sure if it's just in the middle of a bunch of long tests, or if it's hanging on something it really shouldn't be hanging on.

So, I was wondering if there is a way to get them to run verbosely? So I can see which test we are actually on? I just want the command line to spit out something like:

Running test <testName>: Started...Complete (231 sec)

I've looked through the Gradle documentation and haven't seen anything that shows how this might be done. Granted, I am a little new at this, so... If anyone has an idea how this could be done? I would prefer to have a flag that just does it, but if it can be done with some scripting I'm willing to learn. Just point me in that direction...

Upvotes: 2

Views: 310

Answers (1)

Opal
Opal

Reputation: 84756

Have a look at this DSL doc. In general what You need is make use of beforeTest and afterTest closures. You can keep the invocation start in a global map.

def times = [:]

test {
   beforeTest { td ->
      times[td.name] = System.currentTimeMillis()
      println "$td.name started"
   }

   afterTest { td ->
      println "$td.name finished in ${System.currentTimeMillis() - times[td.name]}"
   }
}

I'm not sure if this is synchronous. You need to try.

Upvotes: 2

Related Questions