Reputation: 724
I am building a Grails REST application and I have written my Functional Tests using Spock. Note that these functional tests are for REST services only.
class LoginFunctionalSpec extends Specification {
def setUp() {
// here I want to access grailsApplication.config
}
}
I have already tried the following approaches:
But none of them provide me grailsApplication.config inside my functional test.
Is there any way to achieve this ?
@dmahapatro
I am not using Geb because I am testing REST services and there is no browser automation required.
As I said in point#1 grails Application is not being auto-injected.
class LoginFunctionalSpec extends Specification {
def grailsApplication
def setUp() {
def port = grailsApplication.config.mongo.port //throws NPE
}
}
It throws a NPE saying that config property is being invoked on null object.
Upvotes: 3
Views: 4483
Reputation: 6954
Are you running your test in integration test phase or functional test phase?
You need to extend from IntegrationSpec to get autowiring in integraton test phase but you are talking about functional tests here... Because of grails running your tests in the same JVM as the application under tests you don't really need to use RemoteControl but I always do anyway in my functional tests as it seems much cleaner to me and is a really powerful technique if your tests and application under tests are not running in the same JVM.
Upvotes: 1
Reputation: 50245
I think you do not need to inject anything explicitly. grailsApplication
is available in the tests by default.
class LoginFunctionalSpec extends Specification {
def setUp() {
grailsApplication.config.blah //should work
}
}
Note-
Spock does not provide direct support for functional tests. You need to use Geb for proper functional tests.
Upvotes: 3