Testing van code die een database gebruikt is uitdagend — je hebt realistisch gegevensgedrag nodig zonder instabiliteit of traagheid. Benaderingen omvatten testdatabases, in-memory databases, transacties/rollback en mocking van de datalaag — elk met afwegingen.
De uitdaging
Database-interacting code needs testing, but databases bring challenges:
→ real DB → realistic but SLOWER; needs SETUP and CLEANUP (state between tests)
→ shared state → tests can interfere (order dependence, flakiness)
→ mocking the DB → fast but may not catch real query/integration bugs
→ Choose an approach balancing realism, speed, and isolation.
