Unit testing ตรวจสอบ หน่วย (unit) ของโค้ดแต่ละหน่วย (ฟังก์ชัน, เมธอด, คลาส) ใน สภาวะแยกเดี่ยว (isolation) — ตรวจสอบว่าแต่ละชิ้นส่วนเล็กๆ ทำงานได้อย่างถูกต้องด้วยตัวมันเอง unit test มีความรวดเร็ว มุ่งเน้นเฉพาะจุด และเป็นรากฐานของกลยุทธ์การทดสอบที่ดี
unit test คืออะไร
A UNIT test verifies the smallest testable piece (a function/method) in ISOLATION:
→ test ONE thing; give inputs, check the output/behavior
→ ISOLATED from dependencies (database, network, other units) — mock/stub those
→ FAST (no real I/O), focused, deterministic
