集成测试注入Grails服务 [英] Integration testing Grails services with injection

查看:120
本文介绍了集成测试注入Grails服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在集成测试我的Grails服务时遇到问题,因为所测试的服务没有被注入到我的测试中。我遵循了其他问题的答案,其中在Stackoverflow上,但仍然无法注入我的服务。以下课程位于 /< project_root> / test / integration / com / example 下:

  package com.example 
$ b $ import Grails.test.GrailsUnitTestCase
$ b $ class MyServiceIntegrationTest扩展GroovyTestCase {

MyService服务;

public void testService(){
assert service!= null
}
}

我已经尝试从命令行( grails test-app )执行这两个命令,并且从IDEA中导致相同失败,即 service null



这是Grails 1.3.6

有关如何让我的集成测试正常工作的任何建议吗?

解决方案 Autowiring在集成测试中的作用与框架的其他部分一样,所以您需要确保该属性的名称与服务一样,除了使用相应的unCamelCase。

  class MyServiceIntegrationTest扩展了GroovyTestCase {
def myService

}

假设您的服务是名为MyService的对象。


I am having problems integration testing my Grails service because the service under test is not being injected in to my test. I have followed the advice from answers to questions else where on Stackoverflow but as yet can not get my service injected. The following class is under /<project_root>/test/integration/com/example:

package com.example

import grails.test.GrailsUnitTestCase

class MyServiceIntegrationTest extends GroovyTestCase {

    MyService service;

    public void testService() {
        assert service != null
    }
}

I have tried executing both from the command-line (grails test-app) and from within IDEA both result in the same failure, namely service is null

This is Grails 1.3.6

Any suggestions on how to get my integration test working please?

解决方案

Autowiring works the same way in integration tests as in other parts of the framework, so you need to make sure the property is named like the service except with the appropriate unCamelCase.

class MyServiceIntegrationTest extends GroovyTestCase {
    def myService

}

Assuming your service is an object named MyService.

这篇关于集成测试注入Grails服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆