Reputation: 63
I am making some integration tests for an app, testing routes that modify the database. So far, I have added some code to my tests to delete all the changes I have made to the DB because I don't want to change it, but it adds a lot of work and doesn't sounds right. I then thought about copying the database, testing, deleting the database in my testing script. The problem with that is that it is too long to do. Is there a method for doing that ?
Upvotes: 1
Views: 1166
Reputation: 2708
You can start a database transaction at the beginning of a test and then roll it back. See the following post for details: https://lostechies.com/jimmybogard/2012/10/18/isolating-database-data-in-integration-tests/
Upvotes: 1
Reputation: 2293
I see two possible ways to solve your problem:
Both approaches solve your problem, you can just shutdown db/container and run it again, db will be clean in that case and you don't have to care about it. Just run new one. However there are some peculiarities:
In-memory is easier to implement and use, but it may have problems with dialects, e.g. some oracle sql commands are not available for H2. And eventually you are running your tests on different DB
Docker container with db is harder to plugin into your build and tests, but it doesn't have embeded DB problems with dialects and DB in docker is the same as your real one.
Upvotes: 1