Stack Exchange
Accessing servletContext from a service within an integration test
I am trying to access the servletContext (application context) from a service into an integration test. 
Here is how I try to allow it into my integration test: 
import org.codehaus.groovy.grails.web.context.ServletContextHolder as SCH 

class ScraperServiceIntegrationTests extends GroovyTestCase {
   ScraperService scraperService

    def testStoring() {
        scraperService = new ScraperService()
        scraperService.servletContext = new SCH() 
        scraperService.storing()
        ...
    }
    ...
}

Here is how I use the servlet context in my service: 
class ScraperService {

    static transactional = true
    def servletContext 

    synchronized def storing() {
        servletContext.numberOfCreditProvider = "whatever"
        ...
    }
    ...
}

I get the following error message: 
No such property: numberOfCreditProvider for class: org.codehaus.groovy.grails.web.context.ServletContextHolder

How can I solve this error?

You're assigning your servletContext in your test to the ServletContextHolder instead of the actual context itself.
You probably want this in your test:
import org.codehaus.groovy.grails.web.context.ServletContextHolder as SCH

def testStoring() {
    scraperService = new ScraperService()
    scraperService.servletContext = SCH.servletContext
    scraperService.storing()
    ...
}


That was it. Thank you both for your help.

org.codehaus.groovy.grails.web.context.ServletContextHolder.getServletContext()

