在集成测试中注入服务的问题

时间:2013-02-05 08:54:42

标签: testing grails integration-testing grails-2.1

我遇到类似的问题,Integration testing Grails services with injection使用此代码:

@TestFor(DocumentosService)
class DocumentosServiceTest extends GroovyTestCase  {
    def myService
    void testEnvioEmailDocumento() {
        assert myService != null
    }
}

执行测试时,myService始终为null。 为什么我的服务没有被注入? 我正在使用grails 2.1

根据Burt Beckwith的指示更新(2013年2月6日):

class DocumentosServiceTest extends GroovyTestCase  {
    def myService
    def documentosService
    void testEnvioEmailDocumento() {
        assert documentosService != null
        assert myService != null
    }
}

现在documentosService也是null。

1 个答案:

答案 0 :(得分:0)

删除@TestFor(DocumentosService),因为那是单元测试。为服务添加常规依赖注入,在这种情况下,它看起来像def documentosService

相关问题