我有依赖服务的服务,例如:
class ParserService {
def depService;
private def parseLine(lineParts) {
...
def set = depService.findItemByName(tmpModule.name);//depService == null
...
我尝试实现集成测试,例如:
@TestFor(ParserService)
class ParserServiceTest extends IntegrationSpec {
def "should not parse comment"() {
when:
...
def resultList = service.parseAnnotations(inputStream);
资源.groovy:
beans = {
}
我有 NullPointerException: depService - null
最佳答案
@TestFor
注释仅用于单元测试。集成测试像普通的 bean 一样工作,因此如果您将服务定义为类中的属性,例如在 Controller /服务/域类中,Grails/Spring 将在您的测试中注入(inject)您的依赖项。
关于 chalice 2.4.4 : services does not inject: integration test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30637838/