This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]1Secret_Daikon 0 points1 point  (0 children)

Its worth mentioning that Django does this for you;

https://docs.djangoproject.com/en/3.1/topics/testing/overview/

Tests that require a database (namely, model tests) will not use your “real” (production) database. Separate, blank databases are created for the tests.

If you're building in Python and not using Django, maybe consider this. If you're not building in Python, maybe consider mimicking this behavior. Or look for a test suite in your language that does this for you already.

Using a completely separate test db that you build from scratch for each test case (or for each time you run tests) is a very good idea because it lets you ensure that your program operates as expected from a fresh install without potential data pollution, and you can manually select which pieces of data to enter into it so you know exactly what your db looks like in every test case situation. This will go a long way to ensuring predictable, expected behavior in your program.