集成测试注入Grails服务 [英] Integration testing Grails services with injection
问题描述
我在集成测试我的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
有关如何让我的集成测试正常工作的任何建议吗?
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屋!