Details
Description
I have seen a very strange behaviour with ConfigurationHolder.config during tests.
I implemented a very simple util class that uses the ConfigurationHolder.
import org.codehaus.groovy.grails.commons.ConfigurationHolder class SomeUtils { static config = ConfigurationHolder.config static final CONSTANT = "I am constant, don't change me" static codec() { config.grails.views.default.codec } }
unit test
import grails.test.* class SomeUnitTests extends GrailsUnitTestCase { void test1() { println SomeUtils.CONSTANT } }
integration test
mport grails.test.*
class SomeIntegrationTests extends GrailsUnitTestCase {
void test1() { assertEquals 'none', SomeUtils.codec() }
}
running the tests results in the below:
- grail test-app -unit is fine
- grail test-app -integration is fine
- grail test-app -unit -integration results in ConfigurationHolder.config = null in the integration tests
It all comes down to accessing the CONSTANT in the unit test. If this is removed the integration test runs fine again.
ConfigurationHolder.config is null in unit tests. You're initializing SomeUtils by accessing the constant, so SomeUtils.config is being set to null. I'm assuming due to the behavior you're seeing that the unit test phase and integration test phase are sharing a VM, so SomeUtils.config is still null when you go to access it in the integration test.
If you update your SomeUtils.codec() to look like this your tests should pass: