i've one service which is extending base service and in base service one more service is wired with @Autowired annotation because of that grails service unit tests are not passing
class UserService extends BaseService{
def getUser() {
def u = [:]
u.name='jason'
return u
}
}
import org.springframework.beans.factory.annotation.Autowired
class BaseService {
@Autowired(required = true)
UtilService utilService
}
import grails.test.mixin.*
import org.junit.*
@TestFor(UserService)
class UserServiceTests {
void testSomething() {
fail "Implement me"
}
}
while running $grails test-app i'm getting below error
| Failure: testSomething(com.krish.web.service.UserServiceTests)
| org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exce
ption is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.krish.web.service.UtilService ProcurementBase
Service.utilService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.krish.web.ser
vice.UtilService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.spring
framework.beans.factory.annotation.Autowired(required=true)}
at grails.test.mixin.services.ServiceUnitTestMixin.mockService(ServiceUnitTestMixin.groovy:54)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.krish.web.service.UtilService Ba
seService.utilService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.krish.web.s
ervice.UtilService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.spri
ngframework.beans.factory.annotation.Autowired(required=true)}
... 1 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.krsih.web.service.UtilService] found for de
pendency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annota
tion.Autowired(required=true)}
grails version is 2.1.0
can anyone help how to wire beans for unit test?