【问题标题】:How to Grails 3 integration test in IntelliJ IDEA如何在 IntelliJ IDEA 中进行 Grails 3 集成测试
【发布时间】:2016-05-29 21:26:45
【问题描述】:

我无法在 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 明确指定环境

【问题讨论】:

    标签: grails intellij-idea integration-testing grails-3.0


    【解决方案1】:

    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" />');
        }
    }
    

    【讨论】:

    • expect: 块中调用assertOutputEquals 有点不寻常。我认为更典型的做法是applyTemplate('...') == 'Hello World'。通常在expect: 下,您将拥有计算结果为真或假的表达式,而不是调用会引发异常以指示失败的方法。
    【解决方案2】:

    Spock 测试(“规范”)通过 when:then:expect: 等的存在来识别哪些方法是测试。

    【讨论】:

      猜你喜欢
      • 2011-07-11
      • 2017-02-07
      • 2019-12-24
      • 1970-01-01
      • 2018-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-27
      相关资源
      最近更新 更多