You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
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:
But it seems to me that ought to be the default behaviour
The text was updated successfully, but these errors were encountered: