"Couldn't find ApplicationContext, first configure Grails"
We have a plugin project with some classes and domain services, etc. We have an application project that uses a plugin project. This is the big picture. The integration test (which ends up in the DB) does not work in the plugin project because it has no application context, so we run the integration tests in the main application project.
We have a very simple integration test:
/*@TestFor(Site)*/
class SiteIntegrationSpec extends IntegrationSpec {
static transactional=false;
def setup() {
}
def cleanup() {
}
void "test something"() {
Site site
when:
site = Site.get(1L)
then:
site.name == "root"
}
}
A site is just a domain object like this:
class Site {
String name
// some more fields here
}
NOTE. Tried this with TestFor (Site), not commented as well - same error.
If I look in the DB, there are site records there.
OK, just found another clue. The SiteIntegrationSpec test worked. It worked before we added the second ParamIntegrationSpec test. If we run any of these tests ourselves:
test-app --stacktrace --verbose ParamIntegrationSpec
work
test-app --stacktrace --verbose SiteIntegrationSpec
work
but if we run both of them:
test-app --stacktrace --verbose *IntegrationSpec
The SiteIntegrationSpec test always fails with the above exception.
any ideas?
Full stack trace:
java.lang.IllegalStateException: Could not find ApplicationContext, configure Grails correctly first
at grails.util.Holders.getApplicationContext(Holders.java:97)
at grails.test.spock.IntegrationSpec.$spock_initializeSharedFields(IntegrationSpec.groovy:41)
Note 2:
test-app --stacktrace --verbose -integration
gives the same error when testing the site.
source to share
Thanks to user 1690588 I found the problem. The Grails IntegrationSpec IllegalStateException gave me a clue: The breakdown was not in the test that failed, but in the test that passed!
Basically, the ParamIntegrationSpec test had:
@TestFor(ParamService)
This kills any subsequent test. I don't know what TestFor does, only saw it in all examples.
To fix, just remove this line from the working test.
source to share