Reputation: 3723
I need to determine if my Grails application is currently under testing. I cannot use if (Environment.getCurrent() == Environment.TEST)
, because my current environment is Environment.CUSTOM
with name jenkins. Is there an other way to find out if it's currently under testing?
Upvotes: 0
Views: 219
Reputation: 12334
One approach I've used is to set an environment variable by hooking into the eventTestPhaseStart
GANT event. You can do this by creating a script named Events.groovy
in /scripts
.
<project dir>/scripts/Events.groovy
:
eventTestPhaseStart = { args ->
System.properties['grails.testPhase'] = args
}
You can use it like so to determine if the app is under testing:
if (System.properties['grails.testPhase'] != null)
println "I'm testing!"
You can also use it to have specific behavior for a particular test phase:
if (System.properties['grails.testPhase'] == 'integration')
println "Do something only when running integration tests."
Upvotes: 2