1

I am writing regression testing for a large web application created with Grails 2.3.5. The unit tests use spock framework, the integration tests were written using JUnit framework, and functional tests use spock and geb. DbUnit is used with the integration and functional tests to provide a simple database to test. All tests run fine when calling:

grails test-app unit:
grails test-app functional:
grails test-app unit: functional:
grails test-app integration: functional:
grails test-app unit: aUnitTest integration: aTestController functional:

but when I call:

grails test-app
grails test-app unit: integration: functional:

the functional tests fail with this error:

junit.framework.AssertionFailedError: Condition not satisfied:

driver.currentUrl == urlPrefix + "/login"
|      |          |  |         |
|      |          |  |         http://localhost:8099/FOOBAR/login
|      |          |  http://localhost:8099/FOOBAR
|      |          false
|      |          19 differences (75% similarity)
|      |          http://localhost:8099/(GrailsUnitTestMixin)/login
|      |          http://localhost:8099/(FOOBAR)/login
|      http://localhost:8099/GrailsUnitTestMixin/login
FirefoxDriver: firefox on XP (c9e919fe-1046-488a-af0f-25e9a572db3b)

at MySpec.Login with username and invalid password(MySpec.groovy:31)

As you can see, the base URL changes causing tests to fail. What might cause this? Any ideas on where to begin looking? The in-memory database is currently set to create-drop so it should clear between unit, integration, and functional tests. DbUnit is connected in Bootstrap.groovy which starts up and tears down before and after the application is run. Any help in tracking this down is greatly appreciated.

These articles were the closest I could find to what my issue might be:

Grails Spock integration test redirectedUrl different between localhost test-app and build server test-app

grails "test-app" fails for functional geb+spock test but "test-app -functional" is successfull

Community
  • 1
  • 1
evanden
  • 11
  • 3

1 Answers1

1

There is definitely some global state bleed between test phases here. The only suggestion I would have is to watch at which point the context path changes to include GrailsUnitTextMixin. Is it when you click a link? Or are you getting redirected to that url? Run your tests in debug mode and try to track it down.

The fact that the context is set to a name of a class which gets used whenever you use @TestFor in unit tests would suggest that some global/static variable gets set or modified during unit test phase yet you said that if you run unit tests and functional test together you don't observe this behaviour and you get it only when you run all three test phases together...

erdi
  • 6,944
  • 18
  • 28
  • I searched for possible ways that the tests could bleed over and I have a hunch it is from some of the Groovy MetaClass 'black magic' I had done during testing. I found this article helpful: http://www.jworks.nl/2011/08/12/friday-repost-remove-groovy-metaclass-methods/ I'll see if this can fix my issue. After doing some reading I'm sure there is some kind of bleed between tests. Just a matter of figuring out what it is. Thanks. – evanden Feb 25 '14 at 18:46