Chapter 9. Database Testing
So far, we have been trying to write unit tests and isolate the tested code. The unit tests are the best approach, and you should always start with unit testing, but when you are testing code, sooner or later you will come across code that needs to read or write to a database. Database testing is tricky, and there are several options to test it. You have to decide on which level you need to test code. The problem comes with database complexity. Database and data in the database are as important as working code, and you need to be sure that everything works together.
The following different approaches can be tried to test a database:
- Use mocking to replace code that connects to the database
- Use a specific database driver ...