This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Description
I have a Grails 5.0.x plugin project and I have noticed that in unit tests, if I change the config in a test method in order to test aspects of the class under test, then that change persists after the end of the test method - causing difficult to find side effects.
For example - consider the following test methods that test a class AClass
def 'test using configA'() {
given:
config.aProperty = 'A'
expect:
// Some behaviour of the class works as expected
AClass.someMethod() == 'resultThatDependsOnConfigBeingA"
}
def 'test using configB'() {
given:
config.aProperty = 'B'
expect:
// Some behaviour of the class works as expected
AClass.someMethod() == 'resultThatDependsOnConfigBeingB"
}
def 'testing something else'() {
given:
// config.aProperty has now been changed to 'B' for this test, because it runs later
expect:
// Behaviour here depends on whether this test method runs before or after the above methods - so is fragile to changes in other test methods
}
The issue appears to be that the changes to the config persist after a test method has finished, which pollutes the fixtures for all other tests in the test class.
I have managed to workaround this by calling the following in the setup() method of the test class:
config.clear()
config.refresh()
But it seems to me that ought to be the default behaviour