Does geb reset the database after each test?
I've been collecting my legs from Geb to Grails, but there isn't a lot of documentation out there on how it behaves. For example, how does geb handle rollbacks? From what I observe, it launches the application and runs the test in the browser itself, without disabling it between tests.
What happens to the database data when one spec (spec A) modifies an object (object Z) and several tests later, another spec (spec B) modifies the same object? Does geb send the database a virgin state to it every time the spec is run? I am trying to confirm because I have geb tests that run fine when run individually, but when I ran them as a set some of them failed and the best reason I could think of is the data is not in pristine state when the second test was carried out on it. Any thoughts?
source to share
Geb tests and functional tests in general are very different from unit and integration tests. Unit and integration tests run in the same JVM, and the test runner starts a transaction before each test and rolls it back after running the test, which causes the database to be dumped, but it really just checks if the database has changed. But any data inserted into the database before the tests start (for example, from BootStrap) will be available for each test.
But functional tests usually run in one JVM, but they make remote calls to your application running in the second JVM. This limits what you can do during tests, for example you cannot manipulate metaclasses or change Spring bean instance variables, and you cannot start and rollback transactions to isolate data changes between tests. You can do any of these things, but they will only affect the local JVM.
Geb can make these changes remotely, but that would require changing your application to add a controller or some other way to make remote calls, but it doesn't.
In general, tests should not be ordered and should be independent, but I believe that when doing functional tests it makes sense to break this rule and order them when an earlier test makes some insertions or other changes and subsequent tests further work and / or check for based on earlier changes. I've also added validation-only controller actions that can be used to roll back changes (via transaction or delete inserted data, undo updates and deletes, etc.) and make other changes to help with the tests, but that should be for it to be only available during testing and did not become a significant security risk.
source to share