【问题标题】:Grails test integration service injectionGrails 测试集成服务注入
【发布时间】:2015-01-21 08:45:41
【问题描述】:

我想做一个完整的集成测试,它使用将调用其他服务的服务(我使用的是 grails 2.4.3)。 这一切都很好,但是当一个服务中有一个服务时,它只会 2 级深度并且它不会更深
问题是:如何使测试使用所有必要的子服务

class ImportServiceTests extends GroovyTestCase {  

    def grailsApplication
    def fatherService

    def setup() {
    }

    def cleanup() {
    }

    void 'test1'() {
        String a= fatherService.function() // ->subService -> null
    }
}

【问题讨论】:

  • 使用 grails 2.4.x spock 是默认的测试框架,您的集成规范应该扩展 grails.test.spock.IntegrationSpec。你对这个基类有同样的问题吗?
  • 是的,扩展 grails.test.spock.IntegrationSpec 也会发生同样的情况
  • 我们没有这样的问题。你能附上你的项目吗?至少给出被测试的服务和方法的代码。

标签: grails testing groovy integration-testing


【解决方案1】:

我的错误出现在 grails 参数中的测试调用中

修正自

test-app -unit: ...package.class.method -Dgrails.env=integration

test-app integration: ...package.class.method

【讨论】:

  • 这对我很有帮助。如果没有“集成:”标志,我们无法进行集成测试来注入协作服务。
猜你喜欢
  • 2013-01-03
  • 1970-01-01
  • 1970-01-01
  • 2017-03-08
  • 2016-12-03
  • 1970-01-01
  • 1970-01-01
  • 2012-08-31
  • 1970-01-01
相关资源
最近更新 更多