Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to config in GrailsUnitTestCase implementor are not reset between test methods - causing side effects #186

Open
boardbloke opened this issue Dec 16, 2021 · 0 comments

Comments

@boardbloke
Copy link

boardbloke commented Dec 16, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant