如何在IntelliJ IDEA中进行Grails 3集成测试

如何在IntelliJ IDEA中进行Grails 3集成测试,grails,intellij-idea,integration-testing,grails-3.0,Grails,Intellij Idea,Integration Testing,Grails 3.0,我无法在IntelliJ IDEA中运行集成测试。下面是由grails create integration test生成的测试模板 @Integration @Rollback class TestServiceIntSpec extends Specification{ void "test something"() { //some code here } } 以下是我尝试从junit配置运行它时的输出: Process finished with exit code 0 Em

我无法在IntelliJ IDEA中运行集成测试。下面是由grails create integration test生成的测试模板

@Integration
@Rollback
class TestServiceIntSpec extends Specification{
 void "test something"() {
   //some code here
 }
}
以下是我尝试从junit配置运行它时的输出:

Process finished with exit code 0
Empty test suite.

似乎grails也在使用development env如果我在IDE中运行这个测试,我必须通过-Dgrails显式地指定env。env=test

Spock测试(“规范”)通过
的存在来确定哪些方法是测试,当:
然后:
,或者
期望:
,等等。

HypeMK的答案是正确的。为了详细说明,以下测试可能不会运行,因为它不存在概括测试规范性质的spock关键字(expect、when、then等):

@TestFor(BeanFormTagLib)
类BeanFormTagLibSpec扩展了规范{
def安装程序(){}
无效“地址设置”(){
assertOutputEquals('Hello World','');
}
}
在这里,我们通过添加“expect”关键字来纠正此问题:

@TestFor(BeanFormTagLib)
类BeanFormTagLibSpec扩展了规范{
def安装程序(){}
无效“地址设置”(){
期望:
assertOutputEquals('Hello World','');
}
}

expect:
块中调用
assertOutputEquals
是一件有点不寻常的事情。我认为更典型的做法是像
applyTemplate(“…”)==“helloworld”
。通常在
expect:
下,表达式的计算结果为true或false,而不是调用将抛出异常以指示失败的方法。
@TestFor(BeanFormTagLib)
class BeanFormTagLibSpec extends Specification {
    def setup() {}

    void "address setup"() {
        assertOutputEquals ('Hello World', '<g:beanFormTagLib domainName="com.myapp.Address" />');
    }
}
@TestFor(BeanFormTagLib)
class BeanFormTagLibSpec extends Specification {
    def setup() {}
    void "address setup"() {
        expect:
        assertOutputEquals ('Hello World', '<g:beanFormTagLib domainName="com.myapp.Address" />');
    }
}