การทดสอบโค้ดที่ใช้ ฐานข้อมูล เป็นเรื่องท้าทาย — คุณต้องการพฤติกรรมข้อมูลที่สมจริงโดยไม่มี flakiness หรือความช้า แนวทางต่าง ๆ ได้แก่ test database, in-memory database, transaction/rollback, และ การ mock ชั้นข้อมูล — แต่ละแบบมี trade-off
ความท้าทาย
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.
