2015-01-21 117 views
1

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

class ImportServiceTests extends GroovyTestCase { 

    def grailsApplication 
    def fatherService 

    def setup() { 
    } 

    def cleanup() { 
    } 

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

随着g rails 2.4.x spock是默认的测试框架,您的集成规范应该扩展grails.test.spock.IntegrationSpec。你对这个基类有同样的问题吗? – droggo 2015-01-21 11:34:55

+0

是的,扩展grails.test.spock.IntegrationSpec – 2015-01-21 13:06:34

+0

也是如此。我们没有这样的问题。你能够附加你的项目吗?至少给出经过测试的服务和方法的代码。 – droggo 2015-01-21 16:37:20

回答

1

我的错误是在Grails的测试呼叫参数

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

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

这对我有帮助。没有“集成:”标志,我们无法通过集成测试来注入协作服务。 – Kirby 2015-06-26 18:44:50