r2 - 28 Sep 2008 - 14:54:07 - PanitaMeananeatraYou are here: SETEC Wiki >  Knowledge Web  > SoftwareEngineeringCategory > SoftwareTesting > CH16_Glass-BoxTestCaseDesignTechniques > CH16_4_DataFlowTesting

Data Flow Testing

ลักษณะการ Test Software

  • จะสนใจที่ตัวแปรใน method หรือ function ว่ามีการเกี่ยวโยงหรือว่ามีการอ้างถึงในส่วนอื่นๆของ function นั้น และมีการแยกแยะว่า เป็นการอ้างถึงในลักษณะใด เช่น การคำนวน หรือใช้ในการตัดสินใจ

ในการแยกชนิดตัวแปรชนิดต่างๆ และมีการพิจารณาในการแยกดังนี้

  • Defination คือตัวแปรที่ถูกนิยาม ขึ้น หรือสร้างขึ้นใหม่ใน function หรือ ตัวแปรที่รับค่าเข้ามาใน function

  • Calculation use หรือ c-use คือตัวแปรที่ได้ถูกนิยามไว้่ก่อนหน้า ถูกนำมาใช้ในการคำนวน บวก ลบ คูณ หาร และการแทนค่า เป็นต้น

  • Predicate use หรือ p-use คือตัวแปรที่ได้ถูกนำมาใช้ในเงื่อนไขต่างๆ เช่น if , else

ตัวอย่าง Data Flow Testing

สมมติ code การคำนวนราคาห้องของโรงแรม ที่มีการรับค่า วันที่ checkin ,เวลา checkout ,เวลาที่checkout ที่ช้าไป และราคาห้องต่อคืน


1 function charge_calc(checkin_date,checkout_time,late_checkout_time,room_rate){
2    today = date();
3    expected_checkout_time = 12pm;
4    latest_checkout_time = 6pm;
5    no_of_nights = today-checkin_date;
6    if(late_checkout_time<>"None"){
7       if(late_checkout_time>expected_checkout_time)and(late_checkout_time<=latest_checkout_time){
8          expected_checkout_time = late_checkout_time;
9       }
10   }
11   if(checkout_time > expected_checkout_time) or (checkin_date == today){
12      no_of_nights = no_of_nights + 1;
13   }
14   charge = no_of_nights * room_rates;
15   return charge   
16 }

อธิบาย Code และการกำหนดชนิดตัวแปร

  • พิจารณาจาก code จะเห็นว่าในบรรทัดที่ 1 function จะรับค่าเข้ามา 4 ค่าคือ checkin_date,checkout_time,late_checkout_time และ room_rate ตัวแปร 4 ค่านี้ คือชนิดตัวแปรแบบ Definition คือ ตัวแปนที่ถูกนิยามขึ้นใหม่

  • ในบรรทัดที่ 2 3 และ 4 ก็จะเป็นตัวแปรใหม่ที่ถูกประกาศขึ้นชื่อ today , expected_checkout_time และ latest_checkout_time ตามลำดับ

  • ในบรรทัดที่ 5 จะมี ตัวแปรชื่อ no_of_nights ประกาศขึ้นใหม่เป็นชนิด Defination และ ตัวแปร today และ checkin_date ที่ถูกประกาศก่อนหน้านั้น ได้ถูกใช้ในการคำนวน no_of_nights = today-checkin_date จึงกำหนดชนิดให้เป็น Calculation use หรือ c-use

  • ในบรรทัดที่ 6 late_checkout_time ได้ถูกนำมาใช้ในเงื่อนไข if(late_checkout_time<>"None") จึงเป็นชนิด p-use

  • ในบรรทัดที่ 7 late_checkout_time , expected_checkout_time และ latest_checkout_time ได้ถูกนำมาใช้ในเงื่อนไข if(late_checkout_time>expected_checkout_time)and(late_checkout_time<=latest_checkout_time) จึงเป็นชนิด p-use

  • ในบรรทัดที่ 8 late_checkout_time และ expected_checkout_time ถูกนำมาใช้ ในการคำนวน expected_checkout_time = late_checkout_time; จึงเป็นชนิด c-use

  • ในบรรทัดที่ 11 checkout_time ,expected_checkout_time , checkin_date และ today ถูกนำมาใช้ในเงื่อนไข if(checkout_time > expected_checkout_time) or (checkin_date == today) จึงเป็นชนิด p - use

  • ในบรรทัดที่ 12 no_of_nights ถูกนำมาใช้ในการคำนวน no_of_nights = no_of_nights + 1; จึงเป็น c-use

  • ในบรรทัดที่ 14 charge ถูกสร้างขึ้นมาใหม่ เป็น Defination และ no_of_nights และ room_rate ถูกนำมาคำนวนจึงเป็น c-use

จากการกำหนดชนิดตัวแปร จะได้ตารางดังนี้

Line Category
Defination c-use p-use
1 checkin_date
checkout_time
late_checkout_time
room_rate
   
2 today    
3 expected_checkout_time    
4 latest_checkout_time    
5 no_of_nights today
checkin_date
 
6     late_checkout_time
7     late_checkout_time
expected_checkout_time
latest_checkout_time
8  

late_checkout_time
expected_checkout_time

 
11     checkout_time
exptected_checkout_time
checkin_date
today
12   no_of_nights  
14 charge no_of_nights
room_rate
 

ทำการ Map du-pair ว่า definationตัวไหน ใช้งานแบบไหนระหว่าง c-use หรือ p-use

du-pair

du-pair
Variable
c-use
p-use
1->5
checkin_date  
1->11
  checkin_date
1->11
  checkout_time
1->6
  late_checkout_time
1->7
  late_checkout_time
1->8
late_checkout_time  
1->14
room_rate  
2->5
today  
2->11
  today
3->7
  expected_checkout_time
3->8
expected_checkout_time  
3->11
  expected_checkout_time
4->7
  latest_checkout_time
5->12
no_of_nights  
5->14
no_of_nights  

ต่อไปแยก Defination ทุกๆตัวออกมาจากตาราง ข้างบน

All Definitions

du-pair
Variable
Path
1->5
checkin_date 1-2-3-4-5
1->11
checkout_time 1-2-3-4-5-6-9-10-11
1->6
late_checkout_time 1-2-3-4-5-6
1->14
room_rate 1-2-3-4-5-6-10-11-14
2->11
today 1-2-3-4-5-6-10-11
3->7
expected_checkout_time 3-4-5-6-7
4->7
latest_checkout_time 4-5-6-7
5->12
no_of_nights 5-6-10-11-12

แตก c-uses ทั้งหมดออกมาจากตาราง du-pair

All c-uses

du-pair
Variable
Path
1->5
checkin_date 1-2-3-4-5
1->8
late_checkout_time 1-2-3-4-5-6-7-8
1->14
room_rate 1-2-3-4-5-6-10-11-14
2->5
today 2-3-4-5
3->8
expected_checkout_time 3-4-5-6-7-8
5->12
no_of_nights 5-6-7-9-10-11-12
5->14
no_of_nights 5-6-10-11-14

และสุดท้ายแยก p-uses ออกมา

All p-uses

du-pair
Variable
Path
1->11
checkin_data 1-2-3-4-5-6-10-11
1->11
checkout_time 1-2-3-4-5-6-10-11
1->6
late_checkout_time 1-2-3-4-5-6
1->7
late_checkout_time 1-2-3-4-5-6-7
2->11
today 2-3-4-5-6-10-11
3->7
exptected_checkout_time 3-4-5-6-7
3->11
expected_checkout_time 3-4-5-6-10-11
4->7
latest_checkout_time 4-5-6-7

จากนั้น เราจะ map ตัวแปร กับ path ที่ใช้ทั้งหมด จากจุด defination จนถึงจุดสุดท้ายที่ใช้งาน

All Uses

du-pair
Variable
Path
1->5 checkin_date 1-2-3-4-5
1->11 checkin_date 1-2-3-4-5-6-10-11
1->11 checkout_date 1-2-3-4-5-6-10-11
1->6 late_checkout_time 1-2-3-4-5-6
1->7 late_checkout_time 1-2-3-4-5-6-7
1->8 late_checkout_time 1-2-3-4-5-6-7-8
1->14 room_rate 1-2-3-4-5-6-10-11-14
2->5 today 2-3-4-5
2->11 today 2-3-4-5-6-10-11
3->7 expected_checkout_time 3-4-5-6-7
3->8 expected_checkout_time 3-4-5-6-7-8
3->11 expected_checkout_time 3-4-5-6-10-11
4->7 latest_checkout_time 4-5-6-7
5->12 no_of_nights 5-6-7-9-10-11-12
5->14 no_of_nights 5-6-10-11-14

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

เราจะทำ Test Case มาทดสอบตัวแปรเพื่อให้ได้ครอบทุกตัวที่ใช้ใน function

Test Case
Checkin Date
Checkout Time
Late checkout time
Charge
du-pair
1
12/8/2006
11:30pm
None
$425
1->5
1->11
1->11
1->6
1->7
1->14
2->5
2->11
3->7
3->11
4->7
5->14
2
12/8/2006
2:15pm
2:30pm
$425
1->8
3->8
3
12/8/2006
3:15pm
None
$510
5->12

* อธิบาย

  • ใน Test caseที่ 1 จะเห็นได้ว่า ครอบคลุม ตาราง all uses 12 path จากทั้งหมด 15 path คิดเป็น % ได้คือ 80 % จะเหลือ อีก 3 path ที่เราจะต้องทำ Test Case มาเพิ่ม เพื่อให้ครอบคลุม หมดทั้ง 15 Path
  • ใน Test case ที่ 2 จะเห็นได้ว่า เพิ่มการครอบคลุม อีก 2 path เป็น 14 path จากทั้งหมด 15 path คิดเป็น % ได้คือ 93% จะเหลืออีก 1 path ที่เราจะต้องทำ Test Case มาเพิ่ม เพื่อให้ครอบคลุม หมดทั้ง 15 Path
  • Tese case ที่3 ทำให้ครอบคลุมครบทั้ง 15 path 100% พอดี

References

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


Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: 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