AI กับ Edge Cases และ Negative Scenarios
บทนี้สอนใช้ AI หา edge case และ negative scenario ที่มนุษย์ลืม โดยใช้เทคนิคที่ออกแบบให้ AI คิดในมุมที่เราไม่ได้คิด ไม่ใช่แค่ list สิ่งที่ obvious
จบบทนี้แล้วคุณจะ...
- ใช้ AI brainstorm edge case ได้ครอบคลุมกว่าคิดเอง
- เขียน prompt ที่บังคับให้ AI คิดในมุมที่ผิดเพี้ยน
- รวม edge case ที่ AI gen เข้าสู่ test plan อย่างมีระบบ
- ระบุ "edge ปลอม" ที่ AI สร้างขึ้นมาแต่ไม่ใช่ business risk จริง
มนุษย์มี cognitive bias ที่หลีก edge ออก
นักทดสอบที่มีประสบการณ์มักคิด edge case ใน pattern เดิม:
- empty / null / very long
- max int / min int
- special character ที่เคยเจอ
- timezone ที่เคยทำให้ bug
ปัญหา: ของจริงที่ทำให้ระบบพังมัก:
- combination ของ edge หลายจุดพร้อมกัน
- locale-specific (Turkish "i" → "İ", German "ß" → "ss")
- input ที่ "ไม่ควรเกิดขึ้น" แต่เกิด
- timing race condition ระหว่าง 2 action
AI ไม่ได้คิดแบบมนุษย์ — มันมี exposure ต่อ bug pattern จากหลาย project ใน training data ทำให้นึกถึง case ที่นักทดสอบคนเดียวจะลืม
ขอให้ AI พยายาม break แทนที่จะ test
แทน prompt แบบ "list edge cases for X" ใช้:
You are an adversarial security tester trying to break this system.
Feature: User registration form
Fields: email, password, displayName, age
For each field, list 10 inputs designed to:
- Cause server crash
- Bypass validation
- Exploit business logic
- Trigger unexpected state
- Cause data corruption
For each input, explain:
- What you're trying to break
- Why this might work
- What the system should do instead
ผลที่ได้:
- input ที่ทดสอบ buffer overflow (10MB string)
- SQL/NoSQL injection ใน email field
- Unicode normalization attack (
CafévsCafé) - timing attack กับ password (string compare)
- duplicate registration ผ่าน race condition
หลายอย่างนี้ QA ที่ไม่มี security background จะไม่นึกถึงเอง
Race condition และ state combination
For the e-commerce checkout feature, list 15 scenarios where 2+ things happen
simultaneously and could cause incorrect behavior.
Examples to spark thinking:
- User clicks "Pay" twice quickly
- User changes shipping address while order is processing
- Stock runs out between "add to cart" and "checkout"
- Coupon expires during checkout flow
Continue with more.
AI จะกระจายไปยัง:
- session expire ระหว่าง form submit
- 2 user ซื้อสินค้า last unit พร้อมกัน
- payment provider down ตอน confirm
- email verify link expire ตอน user click
- price เปลี่ยนระหว่าง add cart กับ pay
นี่คือ category ที่ unit test จับไม่ได้แต่กระทบ user จริง
Persona-based edge brainstorm
List 10 unusual user scenarios that the standard test plan often misses.
Examples:
- User on slow 2G network
- User with screen reader (NVDA, JAWS)
- User who left tab open for 24 hours
- User with system clock set wrong
- User using browser zoom 200%
Continue with more, including:
- Mobile-specific
- Accessibility
- Locale / language
- Network conditions
ผลที่ได้:
- user ใช้ browser ภาษาที่ไม่ support
- user มี ad blocker ที่ block analytics script ที่ feature ใช้
- user copy-paste ข้อมูลจาก Word มี hidden formatting
- user roll back time / forward time
- user มี cookies disabled
- user ใช้ Brave + tracking protection
ไม่ใช่ทุก edge ที่ AI gen คุ้ม test
หลังได้ list ยาว ๆ ใช้เกณฑ์:
| เกณฑ์ | คำถาม |
|---|---|
| Likelihood | scenario นี้เกิดในโลกจริงบ่อยแค่ไหน? |
| Impact | ถ้าเกิดแล้ว user เสียหายแค่ไหน? business เสียหายแค่ไหน? |
| Detectability | ถ้าเกิดแล้ว เราจะรู้ภายในเวลาเท่าไหร่? |
| Cost to test | test scenario นี้ใช้เวลา/setup เท่าไหร่? |
| Likelihood | Impact | ตัดสินใจ |
|---|---|---|
| สูง | สูง | ต้อง test |
| สูง | ต่ำ | test ถ้าง่าย |
| ต่ำ | สูง | ต้อง test (catastrophic) |
| ต่ำ | ต่ำ | ข้าม |
ตัวอย่าง:
- "user ใช้เครื่องคิดเลขแทน mouse" → low/low → ข้าม
- "race condition ตอน checkout 2 user ซื้อ last unit" → low/high → test
- "Unicode normalization ใน email comparison" → mid/high → test
- "browser zoom 500%" → low/low → ข้าม (cosmetic)
อย่าเก็บ list ไว้เฉย ๆ
หลัง brainstorm แล้ว:
- กรองด้วยเกณฑ์ likelihood × impact
- แยก edge เป็น: must-test (P0), should-test (P1), nice-to-test (P2)
- P0 → เขียน test case + automate
- P1 → manual test + ดูใน exploratory session
- P2 → log ไว้, revisit เมื่อเปลี่ยน feature
documenting reason: ทำให้ทีมรู้ว่าทำไมเลือก, ทำไมไม่เลือก, รับ accountability ได้
แบบฝึก: brainstorm edge case ของ password reset
ใช้ AI พร้อม pattern adversarial หรือ persona-based brainstorm 15 edge case ของ "password reset via email link" แล้วกรองด้วยเกณฑ์ likelihood × impact ระบุ P0/P1/P2
ดูคำตอบแนะนำ (ตัวอย่าง output แบบ filter)
ตัวอย่าง edge ที่ AI gen ได้:
| Edge case | L | I | Priority |
|---|---|---|---|
| User คลิก reset link หลัง 24 ชม. | สูง | กลาง | P0 |
| User คลิก link ครั้งที่ 2 หลังใช้แล้ว | สูง | สูง | P0 |
| User ขอ reset link หลายครั้ง — link เก่ายัง valid? | กลาง | สูง | P0 |
| Email มี + alias ทำให้ matching ผิด | กลาง | สูง | P0 |
| User เปลี่ยน password เป็น password เดิม | สูง | กลาง | P0 |
| User ใส่ password ที่มี emoji | กลาง | กลาง | P1 |
| Token leak ใน Referer header เมื่อ link มี analytics | ต่ำ | สูง | P0 (security) |
| User คลิก link จากเครื่องอื่น (cross-device) | สูง | กลาง | P1 |
| Email server down ตอนส่ง — user ขอใหม่กี่ครั้งได้? | กลาง | กลาง | P1 |
| Race condition: user เปลี่ยน password 2 หน้าต่างพร้อมกัน | ต่ำ | สูง | P0 |
| User browser auto-clear cookies ระหว่าง flow | กลาง | ต่ำ | P2 |
| Reset link ใน plain HTTP (non-HTTPS) | ต่ำ | สูง | P0 |
| Time zone bug: link expiry คำนวณผิด | กลาง | กลาง | P1 |
| User มี clock skew หนัก (1 ปี) | ต่ำ | กลาง | P2 |
| Brute force token guessing | ต่ำ | สูง | P0 |
P0 = 7 cases ต้อง automate, P1 = 4 manual, P2 = 2 log ไว้
สิ่งที่ต้องเอาติดตัวไปจากบทนี้
- มนุษย์มี bias หลีก edge — AI ใช้ pattern จาก project อื่นมาช่วยขยาย scope
- Adversarial prompt ("พยายาม break") ได้ edge ลึกกว่า "list edge cases"
- Race condition และ persona-based brainstorm ดึง case ที่ unit test จับไม่ได้
- กรองด้วย likelihood × impact ก่อนนำเข้า test plan ทุกครั้ง
- จัดเป็น P0/P1/P2 และ document reason เพื่อให้ทีมตามได้