Why should a testdatabase be created/deleted when testing?

Jonas Grønbek :

I have been assigned with testing a mongodb database from a java backend. I got told that I had to create a database completely utilizing a script for this task.

But I have difficulties understanding the benefit of creating a database from scratch with a script, instead of having a permanent test database. Where I imagine data should be inserted on startup and cleaned on teardown in both cases.

Why is it beneficial from a testing perspective to creating and deleting a database when testing?

tquadrat :

Sometimes tests fail and therefore it may happen that the teardown phase will never be reached.

Furthermore, deleting a database is the fastest and most effective way to clean it, although perhaps not the most efficient way to do so. But it guarantees that you do not forget something in your cleanup routine.

And in particular for performance tests it is important that the database is in exact the same state for each run, otherwise the run times cannot be compared with each other: an improvement in a consecutive run could have been caused just because tablespaces were already increased or similar things, and not because the code optimisation worked …

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=400424&siteId=1