I have been on this path, and here are all the problems that you will encounter:
1) This works well for one record, but what happens when you need 4 other records to create this record? As a result, you create 4 records to test the insertion of one record. This causes all of the following problems.
2) Creating and deleting 4-5 records per test is slow, it will slowly add up and it will take 45 minutes to complete your tests (believe me, I was there). Slow tests mean that you will never run them, which means that they will be broken most of the time and useless.
3) Your deletion will not succeed for any missing foreign key relationship or dependency, and then the data from the garbage will remain in your database. This garbage data causes other failed tests.
In light of this, I beg you to consider two things. First, try using ORM instead of writing all this logic yourself. Then you only need to check your mapping files (or even less depending on the ORM you use) or look at the mockery so that you can isolate the logic of the data access code from direct access to the database.
James avery
source share