Reputation: 1353
I have service with dependency service like:
class ParserService {
def depService;
private def parseLine(lineParts) {
...
def set = depService.findItemByName(tmpModule.name);//depService == null
...
I try to implement integration test like:
@TestFor(ParserService)
class ParserServiceTest extends IntegrationSpec {
def "should not parse comment"() {
when:
...
def resultList = service.parseAnnotations(inputStream);
resources.groovy:
beans = {
}
And I have NullPointerException: depService - null
Upvotes: 0
Views: 762
Reputation: 350
The @TestFor
annotation is only for unit tests. The integration tests work like a normal beans, so Grails/Spring will inject your dependencies in your tests if you define the services as properties in your class, like in a controller/service/domain class.
Upvotes: 1
Reputation: 1987
Your test case should extend the class GroovyTestCase
or IntegrationSpec
and that's pretty much it. Of course the dependency injection then works the usual way
class ParserServiceTest extends IntegrationSpec {
ParserService parserService
def "should not parse comment"() {
when:
...
def resultList = parserService.parseAnnotations(inputStream)
...
Upvotes: 1