You have several options:
Database layout
There are a few tradeoffs to be aware of.
Your tests will become more complex as you have to tune, stall and mock the connection. You can also check sent SQL / commands. It also tends to create an odd type of hard link, which can cause you to perform additional validation / update tests when changing a schema or SQL.
This is generally the cleanest for test isolation, as it reduces the potentially greater dependence on testing. It also speeds up tests and reduces overhead to automate a test suite, for example, in a continuous integration environment.
Recover database with each test
Compromises you need to know about.
This can make your test very slow depending on how much time it actually takes to recreate your database. If the dev database server is a shared resource, additional investment will be required for each developer to have their own db on the server. The server may suffer depending on how often testing takes place. There is additional overhead for running a test suite in a continuous integration environment, since it will require at least, possibly more dbs (depending on how many branches are created at the same time).
The advantage is that it really works through the same code paths and similar resources that will be used in production. This usually helps to identify errors earlier, which is always very good.
Exchange ORM DB
If you use ORM, such as SQLAlchemy, this is an opportunity to replace the underlying database with a potentially faster in-memory database. This allows you to mitigate some of the negatives of both of the previous parameters.
This is not exactly the same database that will be used in production, but ORM should help mitigate the risk that hides the error. Typically, the time to install the database in memory is much shorter than the one supported by the files. It also has the advantage of isolating from the current test run, so you donβt have to worry about managing a shared resource or a final break / clear.
dietbuddha
source share