3 ms·
I keep wondering why people won't test with a real database. Right, you need to create it and clean it up before or after every test, but that's a lot cheaper t
by marvinblum 3y ago
I keep wondering why people won't test with a real database. Right, you need to create it and clean it up before or after every test, but that's a lot cheaper than having to stub everything related to the db.
Also spinning one up locally is easy thanks to Docker.
- drewcoo 3y agoIf you're using a container, you don't need to create the DB or clean it up when you run tests. Just spin up a new container and then throw it away if nothing went wrong.
- patmorgan23 3y agoCreate = spin up Clean up = throw away
- masklinn 3y ago> Right, you need to create it and clean it up before or after every test, but that's a lot cheaper than having to stub everything related to the db. Depends on the bringup cost, although templates help there (create a baseline database, then copy it for each test).
- horeszko 3y agoDocker is great, another option I like to use is sqlite. I'm writing a small and simple application and I'm just using an sqlite database for my tests. I have a helper function to create the db, another to add a table, and then a third to delete the db at the end. So in total 3 functions to setup and teardown a test database. Its super quick because an sqlite db is just a file after all.
- rswskg 3y agoit's a real shame that sqlite and postgres have sql differences, otherwise I'd use it alot more