【问题标题】:Problems injecting services in integration test在集成测试中注入服务的问题
【发布时间】:2013-02-05 08:54:42
【问题描述】:

我有一个与Integration testing Grails services with injection 类似的问题:

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

执行测试时,myService 始终为空。 为什么 myService 没有被注入? 我正在使用 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 也为空。

【问题讨论】:

    标签: testing grails integration-testing grails-2.1


    【解决方案1】:

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

    【讨论】:

    • 这完全没有效果。我会根据您的建议编辑问题。
    • 所以服务的类名是DocumentosServicegrails-app/services下,而测试类在src/test/integration下?尝试运行grails clean - 它通常会解决此类奇怪的问题。
    • grails clean 没有帮助,但测试在test/integration 下,src/test/integration 下没有。如果我把它放在src/test/integration 中,我无法从 GGTS 运行它。
    • 我无法从命令行运行测试。还要指出命令行在test文件夹下而不是src/test下生成测试文件。
    猜你喜欢
    • 2013-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-03
    • 2018-03-26
    • 2016-01-18
    • 1970-01-01
    • 2018-08-27
    相关资源
    最近更新 更多