0
我需要确定我的Grails应用程序当前是否正在测试。我无法使用if (Environment.getCurrent() == Environment.TEST)
,因为我当前的环境是Environment.CUSTOM
,名称为jenkins。是否有其他方法可以确定它是否正在测试中?如何确定Grails应用程序是否正在测试?
我需要确定我的Grails应用程序当前是否正在测试。我无法使用if (Environment.getCurrent() == Environment.TEST)
,因为我当前的环境是Environment.CUSTOM
,名称为jenkins。是否有其他方法可以确定它是否正在测试中?如何确定Grails应用程序是否正在测试?
我使用的一种方法是通过挂接到GANT事件eventTestPhaseStart
来设置环境变量。您可以通过在/scripts
中创建名为Events.groovy
的脚本来执行此操作。
<project dir>/scripts/Events.groovy
:
eventTestPhaseStart = { args ->
System.properties['grails.testPhase'] = args
}
你可以使用它像这样来确定应用是否正在测试:
if (System.properties['grails.testPhase'] != null)
println "I'm testing!"
您还可以使用它有特定的行为对于特定的测试阶段:
if (System.properties['grails.testPhase'] == 'integration')
println "Do something only when running integration tests."
谢谢,这是我一直在寻找的方法。我希望有一些内置的东西。 – 2013-05-10 20:33:56