繁体   English   中英

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

[英]How to Grails 3 integration test in IntelliJ IDEA

我无法在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.

如果我从IDE运行此测试,看起来像grails使用开发环境,我必须通过-Dgrails.env = test明确指定env

Spock测试('规范')通过以下时间确定哪些方法是测试when:then:或者expect:等等。

HypeMK的答案是正确的。 详细说明,以下测试可能无法运行,因为它没有spock关键字的存在,这些关键字概述了测试的规范性质(期望,何时,等等):

@TestFor(BeanFormTagLib)
class BeanFormTagLibSpec extends Specification {
    def setup() {}

    void "address setup"() {
        assertOutputEquals ('Hello World', '<g:beanFormTagLib domainName="com.myapp.Address" />');
    }
}

在这里,我们通过添加“expect”关键字来解决问题:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM