2013-05-10 59 views

回答

2

我使用的一种方法是通过挂接到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." 
+0

谢谢,这是我一直在寻找的方法。我希望有一些内置的东西。 – 2013-05-10 20:33:56

相关问题