Database का उपयोग करने वाले code को test करना चुनौतीपूर्ण है — आपको flakiness या slowness के बिना realistic data behavior चाहिए। दृष्टिकोणों में test databases, in-memory databases, transactions/rollback, और data layer को mock करना शामिल हैं — प्रत्येक के अपने trade-offs के साथ।
चुनौती
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.
