Review และปรับปรุง Test Cases ที่ AI สร้าง
บทนี้สอนวิธีอ่าน test cases ที่ AI gen แบบเป็นระบบ จับ hallucination และ shallow assertion ได้เร็ว เพื่อให้คุณกล้านำเข้า test suite จริงได้อย่างมั่นใจ
จบบทนี้แล้วคุณจะ...
- มี checklist ในการ review test case ที่ AI gen ทุกครั้ง
- จับ hallucination และ plausible-but-shallow ได้เร็วขึ้น
- รู้วิธีแก้ test case ที่ AI gen โดยไม่ต้องเริ่มใหม่
- ตัดสินใจได้ว่าอันไหนพร้อมเข้า suite, อันไหนต้องเขียนใหม่ทั้งหมด
อ่านแบบ "ไม่เชื่อก่อน" ดีกว่า "เชื่อก่อน"
Test case ที่ AI เขียนมา มักดูใช้ได้ในสายตาแรก เพราะ:
- มี structure ครบ (Title, Steps, Expected)
- ใช้ทำนองเดียวกับ test case ที่คุณเคยเห็น
- คำที่เลือกฟังดู professional
ปัญหาคือ "ดูใช้ได้" ไม่เท่ากับ "ใช้ได้จริง" QA ที่ดีจะอ่านงาน AI ด้วย mindset ของ reviewer ไม่ใช่ผู้รับ
หลักง่าย ๆ: ก่อนเชื่อ ให้ลองคัดค้าน 3 ข้อก่อน:
- ข้อนี้ run แล้ว fail จริงไหมถ้า bug จริง?
- ข้อนี้ assert สิ่งที่สำคัญหรือสิ่งที่หาง่าย?
- ข้อนี้ถ้าผ่าน บอกอะไรเกี่ยวกับ feature ได้จริง?
รู้ pattern แล้วจับได้เร็วขึ้นมาก
| Pattern | ลักษณะ | วิธีจับ |
|---|---|---|
| Hallucinated step | step ที่ทำใน UI ที่ไม่มีจริง | run จริงดู / ตรวจกับ design |
| Shallow assertion | "page loads" / "no error" | ถามว่า assert อะไรเฉพาะกับ feature นี้ |
| Duplicate-with-noise | test 5 อัน ทดสอบเรื่องเดียว ต่างแค่ค่า | grep หา pattern คล้ายกัน |
| Missing edge case | ครอบคลุม happy path ครบ แต่ negative ขาด | check กับ business rule list |
| Wrong precondition | ระบุ precondition ที่ไม่ตรงกับ flow | ลองทำ precondition จริง |
| Untestable expected | "user feels happy" / "system works correctly" | ถาม "ตรงนี้วัดยังไง" |
| Ghost reference | อ้าง API/page/role ที่ไม่มีในระบบ | grep code base ดู |
| Out-of-scope creep | gen test สำหรับ feature ที่ไม่ใช่ scope | check กับ requirement |
ใช้ทุกครั้งที่จะนำ test case ของ AI เข้า suite
ผ่าน 7 ข้อนี้ก่อน merge:
- Mapping ไปยัง requirement: แต่ละ test case map กับ acceptance criterion ข้อใดข้อหนึ่งได้
- Assertion มีความหมาย: expected ที่เขียน ถ้าผิดจะรู้ทันที ไม่ใช่ "ดูเหมือนถูก"
- Steps ทำได้จริง: ลอง run mental walkthrough หรือ run จริงในระบบ
- Precondition ครบ: data ที่ต้องมี, state ของระบบ, user role — ระบุชัด
- Edge case อยู่ในรายการ: เช็ก business rule ทั้งหมด มีครบไหม
- ไม่มี duplicate: scenario ที่ทดสอบเรื่องเดียวกันด้วย wording ต่าง — รวมหรือลบ
- Out of scope ไม่หลุดเข้ามา: ลบ test ที่นอก feature นี้
ถ้าผ่านทุกข้อ — ใช้ได้ ถ้าไม่ผ่าน — แก้แล้ว review รอบ 2
บ่อยครั้ง 80% ของ output ใช้ได้ แค่ 20% ที่ต้องปรับ
วิธีแก้ที่ effort น้อยกว่าเขียนใหม่:
- ลบ + รวม: ลบ duplicate, รวม case ใกล้เคียง
- เติม assert: ขยาย "expected" ที่ shallow ให้เฉพาะเจาะจง
- เพิ่ม edge: เติม case ที่หายตาม business rule
- แก้ wording: เปลี่ยน expected ที่กำกวมให้วัดได้
ใช้ AI ช่วยแก้ก็ได้ — ส่ง test case ที่ review แล้วกลับให้ AI พร้อม feedback:
Here are the test cases. Issues to fix:
- TC-3 and TC-4 are duplicates, merge them
- TC-7 expected "page loads" — change to assert specific element with content
- Missing case for lockout email content — add it
- Remove TC-9 (out of scope: SSO)
Output the fixed list in the same format.
ไม่ใช่ทุก output คุ้มที่จะแก้
ใช้กฎคร่าว ๆ:
- ถ้า > 70% ของ test case ใช้ได้ → แก้
- ถ้า 30-70% ใช้ได้ → review prompt เดิม แล้ว gen ใหม่ด้วย prompt ที่ดีกว่า
- ถ้า < 30% ใช้ได้ → เขียนเองเร็วกว่า, AI ขาด context ที่จำเป็น
สาเหตุของ output ที่ใช้ได้น้อย มักไม่ใช่ AI โง่ แต่คือ:
- spec ไม่ชัด AI เลย hallucinate
- ทีมมี convention พิเศษที่ AI ไม่รู้
- feature ซับซ้อนเกินกว่าจะ describe ใน prompt เดียว
แก้ที่ root cause ของ prompt ดีกว่าแก้ output ทุกครั้ง
แบบฝึก: review test case ที่มี issue
อ่าน test case ที่ AI gen ด้านล่าง (สำหรับ login feature) แล้วใช้ checklist 7 ข้อ ระบุ issue และวิธีแก้:
TC-1: Login with valid credentials
Steps: 1. Open page 2. Enter email 3. Enter password 4. Click button
Expected: User is logged in successfully
TC-2: Login with invalid email
Steps: 1. Enter "abc" in email 2. Click button
Expected: Error message shown
TC-3: Login fails when system is down
Steps: 1. Disable backend 2. Try login
Expected: Page shows graceful error
TC-4: SSO login with Google
Steps: 1. Click "Login with Google" 2. Authenticate
Expected: Redirect to dashboard
ดูคำตอบแนะนำ
TC-1: shallow assertion — "logged in successfully" วัดยาก ควร assert URL = /dashboard + welcome message มีชื่อ user
TC-2: precondition ไม่ครบ — ไม่ได้บอกว่า password ต้องกรอกหรือเปล่า, error message เนื้อหาอะไร
TC-3: out of scope — ระบบ down เป็น infrastructure test ไม่ใช่ login feature test
TC-4: out of scope (จาก context "Out of scope: SSO" ใน lesson ที่แล้ว) — ลบ
ผลรวม: ผ่าน checklist 0/4 — ต้อง fix prompt และ gen ใหม่ ไม่คุ้มแก้
สิ่งที่ต้องเอาติดตัวไปจากบทนี้
- อ่านงาน AI ด้วย mindset reviewer ไม่ใช่ผู้รับ
- รู้ failure pattern (hallucination, shallow assert, duplicate) ทำให้จับได้เร็ว
- ใช้ checklist 7 ข้อก่อน merge ทุกครั้ง
- แก้แทนเขียนใหม่ ถ้า > 70% output ใช้ได้
- ถ้า output ส่วนใหญ่ใช้ไม่ได้ ปัญหามักอยู่ที่ prompt ไม่ใช่ AI