Testare il codice che utilizza un database è impegnativo — hai bisogno di un comportamento dei dati realistico senza instabilità o lentezza. Gli approcci includono database di test, database in memoria, transazioni/rollback e mock del livello dati — ognuno con compromessi.
La sfida
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.
