Databases · Middle · Question 64 of 75
Why are integration tests against a real database (e.g. in Docker) often preferred over mocking the database?
- ✓Correct answer: They catch real SQL errors, constraint violations and query behavior that mocks hide
- 2Mocks can't be written for databases
- 3They are always faster than unit tests
Explanation
Run each test in a transaction that rolls back, or reset the schema, so tests stay isolated. Testcontainers makes this convenient.