I've seen a few posts about issues with Grails 2.3.x and integration testing, but nothing has helped my situation yet, so here goes:
I want to test my Grails services against a real live database (Oracle) and so I wrote some integration tests in Spock. No matter which of the recommended approaches I try, I get the same error. I'm hoping it's something simple and dumb, but I fear that there is an issue which needs to be addressed by the Grails team.
Here's the code, properly sanitized to remove any hint of where I work:
package com.mycompany
import grails.test.spock.IntegrationSpec
import spock.lang.*
import com.mycompany.User
class UserServiceSpec extends IntegrationSpec {
UserService userService
def setup() {
}
def cleanup() {
}
void "find a user by their id"() {
when:
User user = userService.find('1234')
then:
user.firstName == 'Brian'
}
}
From everything I've read out there, this is how you do it with Grails 2.3 and beyond. I consistently get the following error
java.lang.IllegalArgumentException: ServletContext must not be null
Any help is always appreciated.
Brian
One thing that can cause that problem is if your
UserServiceSpec
is defined undertest/unit/
instead oftest/integration
where it is supposed to be.