Grails

ConfigurationHolder.config is null for "grails test-app -unit -integration"

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: 1.1, 1.1.1
  • Fix Version/s: 1.2.1
  • Component/s: Testing
  • Labels:
    None
  • Testcase included:
    yes

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.

Activity

Hide
Martin Christiansen added a comment -

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:

ConfigHolderTests.groovy
static codec() { ConfigurationHolder.config.grails.views.default.codec }
Show
Martin Christiansen added a comment - 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:
ConfigHolderTests.groovy
static codec() { ConfigurationHolder.config.grails.views.default.codec }
Hide
Keith Ganger added a comment -

Extending ControllerUnitTestCase for an integration test as described here http://grails.org/Testing+Controllers

Also causes ConfigHolder.config to be null for the entire app

Show
Keith Ganger added a comment - Extending ControllerUnitTestCase for an integration test as described here http://grails.org/Testing+Controllers Also causes ConfigHolder.config to be null for the entire app
Hide
Chad Small added a comment -

related work around that I used when I was getting null pointer on ConfigurationHolder.config in integration test ....

ApplicationHolder.application.config. ...

Show
Chad Small added a comment - related work around that I used when I was getting null pointer on ConfigurationHolder.config in integration test .... ApplicationHolder.application.config. ...
Hide
Burt Beckwith added a comment -
Show
Burt Beckwith added a comment - GRAILS-5686

People

Vote (1)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: