r3 - 28 Sep 2008 - 14:52:16 - PanitaMeananeatraYou are here: SETEC Wiki >  Knowledge Web  > SoftwareEngineeringCategory > SoftwareTesting > CH16_Glass-BoxTestCaseDesignTechniques > CH16_1_StatementTesting


Statement Testing


ลักษณะการ Test Software

  • เหมาะกับทำในระดับ Unit Test
  • ทุกบรรทัดหรือทุกๆ statement มีการทดสอบและ execute
  • ยกเว้น comments และ บรรทัดที่ไม่เกี่ยวข้องกับการ execute
  • ใช้เวลา Test นานที่สุด

ข้อดี

  • เป็นการทดสอบที่ละเอียด เพราะทดสอบทุกๆ Statement ของ code

ข้อเสีย

  • ใช้เวลา Test นานยิ่งโปรเจกใหญ่ยิ่งนาน
  • อาจจะจำเป็นต้องใช้ Test Case มากกว่า 1 case เพราะว่า มีโอกาสที่ case นั้น ทดสอบได้ไม่ครบทุก statement

ตัวอย่าง Statement Testing

สมมติว่ามี code function นับสระในข้อความ
1 while not 'end of file'
2    read string
3    vowels = 0
4    consonants = 0
5    character_position = 1
6    while character_position <= length(string)
7       if string[i] = 'a' or 'e' or 'i' or 'o' or 'u' then
8          vowels = vowels + 1
9      else
10         consonants = consonants + 1
11     endif
12     character_position = character_position + 1
13     endwhile
14 endwhile
15 display vowels, consonants

ตัวอย่างกรณีทดสอบ Statement

ลำดับกรณีทดสอบ
Input
Executed Statement
Expect OutCome?
คำอธิบาย
1
123
1,2,3,4,5,6,7,9,10,11,12,13,14,15
0,3
ถ้าเราทดสอบ input โดยใส่ string คำว่า "123" จะเห็นได้ว่า ทุกๆ while loop ที่เข้าไปเช็คในเงื่อนไขที่บรรทัดที่ 7 ไม่มีตัวอักษรใด ที่อยู่ในข้อความ ทำให้เงื่อนไขงั้นเป็นจริงได้เลย ซึ่งไม่ทำให้เราเข้าถึงทุกๆ statement ของ function นั้นได้
2
Pok
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
1,2

จากนั้น case ที่ 2 ใส่ คำว่า "pok" ตัว 'o' เท่านั้นที่จะทำให้เงื่อนไขที่บรรทัดที่ 7 เป็นจริง

* อธิบายเพิ่มเติม จะเห็นได้ว่า เราต้องกำหนด test case มากกว่า 1 ครั้ง หรืออาจจะโชคดี กำหนดครั้งเดียว เข้าถึงทุก statement ก็ได้

References

1. Software Testing Techniques for Improving Software Quality , White Box Testing


Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r3 < r2 < r1 | More topic actions
 
Powered by SETEC Wiki
Copyright ©2012 by National Electronics and Computer Technology Center, NECTEC.
Ideas, requests, problems regarding SETEC Wiki? Send feedback