Public note เรื่อง Testing Pyramid

สรุปสั้นๆ กลยุทธ์การทดสอบระบบแบบปิระมิด

ผมขอยกภาพประกอบ กลยุทธ์การทดสอบระบบด้วยวิธีปิระมิด จาก Thoughtworks มาเพื่อใช้ประกอบคำอธิบายนะครับ

https://www.slideshare.net/ThoughtWorks/testing-strategies-for-micro-services

Unit Testing

  • สร้างชุดทดสอบระบบในส่วนที่เล็กที่สุดของโปรแกรม
  • function, small unit of code
  • ประกอบด้วย algorithms expectation (ผลลัพธ์ถูกต้อง) และ behavior expectation (พฤติกรรม หรือ ได้โครงสร้างข้อมูลตามที่คาดหวัง)
  • test coverage 100% หากทำได้ (แต่ถ้าเป็น function พวกคำนวน หรือ ส่วน business core, business calculation ควรทำ)
  • ไม่ควรมี dependency กับ class อื่นๆ ถ้าต้อง inject other module นั่นหมายความว่า เขียนไม่ดีแล้ว (Low coupling)
  • React-Component<jest|enzyme>

Contract (Integration)

  • สร้างชุดทดสอบครอบคลุม component ต่างๆ ว่าทำงานร่วมกัน แล้วตรงตามความต้องการหรือไม่ มีการนำ mock, stub มาใช้ในส่วนนี้
  • เช่น ทดสอบ cartService() ซึ่งมี dependencies กับ authenticationService(), PaymentService(), productService() เป็นต้น
  • หาก dependency ที่เหนือการควบคุม เราก็ทำการ mock object เหล่านั้น เช่น paypal, omise payment, etc
  • จะว่าไปเรียก Integration test ก็คงไม่ผิดนัก

End-to-End and System Testing

  • ทดสอบระบบจาก module A -> Z ว่าสามารถทำงานร่วมกัน และให้ผลลัพธ์ตามที่ต้องการ
  • และยังทดสอบด้วยว่า external module ที่ติดต่อนั้นสามารถทำงานร่วมกันได้ดีหรือไม่
  • ทดสอบทุก scenario ที่เป็นไปได้ตั้งแต่ UI แรก หรือ โมดูลแรก เชื่อมต่อไปยัง โมดูลถัดไป จนจบทุกกระบวนการ
  • ใช้ environment ที่คล้าย production

Consumer and UI

  • จะเป็น manual test เสียเป็นส่วนใหญ่
  • หา Exploratory testing หา gaps, improvement, non-functional
  • UI สวยตรงใจไหม สีสวยไม่สวย UX หล่ะเป็นยังไง บลาๆ

และปิดท้ายด้วยรูปนี้ครับ

)

Teerapong Singthong 👨🏻‍💻

Written by

LINE Engineer x Software Craftsmanship

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade