Integration testing Grails services with injection

元气小坏坏 提交于 2019-12-23 04:28:41

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7285270/integration-testing-grails-services-with-injection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!