1. Trang chủ
  2. » Luận Văn - Báo Cáo

bài tập về nhà tuần 10 kiểm thử tích hợp

10 2 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Nội dung

BÀI TẬP V NHÀ TUẦN 10 – Kiểm thử tích hợp Môn học: Kiểm thử đảm bảo chất lượng phần mềm Họ tên: Lê Văn Hùng Mã số HV: 14025012 Giảng viên: TS Phạm Ngọc Hùng Tính tiền vé vào công viên dựa theo điều kiện sau: - Công viên làm việc từ thứ đến thứ Với người lớn (Tuổi >= 13) giá vé 1200 Yên/người Với trẻ em giá vé 800 Yên/người Nếu theo nhóm (Lớn 20 người), với người lớn giá vé 800 Yên/người, trẻ em giá vé 300 yên/người Phiếu giảm giá áp dụng cho người có phiếu giảm giá khơng theo nhóm, giảm 25% tổng số tiền vé Tiền vé sau thu từ phái khách hàng trích khoản để nộp thuế o Nếu số tiền < 10 000 n khơng phải nộp o Nếu số tiền từ 10 000 Yên đến 20000 Yên phải nộp 10% tiền thuế o Từ 20 000 yên trở lên phải nộp 20% tiên thuế Dựa mô tả tốn, chương trình tổ chức thành modules sau: - CheckDay (Module C) – Kiểm tra tính hợp lệ ngày làm việc isCoupon (Module D) – Kiểm tra xem khác hàng có thuộc diện giảm giá khơng TicketPrice (Module B) – Tính tiền vé TotalMone (Module A) – Tính tổng tiền khách hàng phải trả (có tính thuế) Sơ đồ chương trình: TotalMoney (A) TicketPrice (B) CheckDay (C) isCoupon (D) I Chiến lược kiểm thử Top Down Trường hợp C D chưa hoàn thành, B hoàn thành Giả sử ta cần kiểm thử module B (hàm TicketPrice()), hàm CheckDay() isCoupon chưa hoàn thành Ta viết Stub tương ứng với case hàm TicketPrice() public boolean stub_checkday1(int day) { return true; } public boolean stub_checkday2(int day) { return false; } public boolean stub_isCoupon1(boolean isCoupon, int numOfPerson) { return true; } public boolean stub_isCoupon2(boolean isCoupon, int numOfPerson) { return false; } Với stub ta kiểm thử hàm TicketPrice Giả sử chọn stub_checkday1() stub_isCoupon1(): public double TicketPrice(int old, boolean isCoupon, int numOfPerson, int day) { if (stub_checkday1(day)) { if (numOfPerson >= 20) { if (old >= 13) price = else { price = } } else { if (old > 13) price = else { price = } } numOfPerson * 800; numOfPerson * 300; numOfPerson * 1200; numOfPerson * 800; if (stub_isCoupon1(isCoupon, numOfPerson)) { price -= price * 0.2; } return price; } return -1; } Chọn phương pháp kiểm thử hộp đen với phương pháp kiểm thử giá trị biên để kiểm thử hàm TotalMoney Testcase {12, true, 20, 4} {13, true, 20, 4} {12, true, 19, 4} {13, true, 20, 4} EO 4800.0 10800.0 12160.0 19200.0 Result Pass Pass Pass Fail Tương tự với stub lại Trường hợp hoàn thành C mà chưa hoàn thành D Giả lập stub sau: public boolean stub_isCoupon1(boolean isCoupon, int numOfPerson) { return true; } public boolean stub_isCoupon2(boolean isCoupon, int numOfPerson) { return false; } Giả sử chọn stub_isCoupon1(): public double TicketPrice(int old, boolean isCoupon, int numOfPerson, int day) { if (checkday(day)) { if (numOfPerson >= 20) { if (old >= 13) price = numOfPerson * 800; else { price = numOfPerson * 300; } } else { if (old > 13) price = numOfPerson * 1200; else { price = numOfPerson * 800; } } if (stub_isCoupon1(isCoupon, numOfPerson)) { price -= price * 0.2; } return price; } return -1; } Áp dụng phương pháp kiểm thử hộp đen ta có: Testcase {12, true, 20, 1} {13, true, 20, 1} {12, true, 19, 1} {13, true, 20, 1} {12, true, 20, 4} {13, true, 20, 4} {12, true, 19, 4} {13, true, 20, 4} EO -1.0 -1.0 -1.0 -1.0 4800.0 10800.0 12160.0 19200.0 Result Pass Pass Pass Pass Pass Pass Pass Fail Tương tự stub_isCoupon2(): Trường hợp hoàn thành D mà chưa hoàn thành C Ta viết stub cho module C public boolean stub_checkday1(int day) { return true; } Với public boolean stub_checkday2(int day) { return false; } stub_checkday1() Ta có: public double TicketPrice(int old, boolean isCoupon, int numOfPerson, int day) { if (stub_checkday1(day)) { if (numOfPerson >= 20) { if (old > 13) // Chen loi o day, thieu dau price = numOfPerson * 800; else { price = numOfPerson * 300; } } else { if (old > 13) price = numOfPerson * 1200; else { price = numOfPerson * 800; } } = if (isCoupon(isCoupon, numOfPerson)) { price -= price * 0.2; // Lỗi (0.25 0.2) } return price; } return -1; } Áp dụng phương pháp kiểm thử hộp đen ta có: Testcase {14, true, 20, 4} {13, true, 20, 4} {14, true, 19, 4} {13, true, 19, 4} {14, false, 20, 4} {13, false, 20, 4} {14, false, 19, 4} {13, false, 19, 4} EO Result 16000 16000 15200 11400 16000 16000 15200 15200 Pass Fail Pass Fail (12160) Pass Fail Fail Fail Trường hợp A hoàn thành, B chưa hoàn thành Áp dụng chiến lược kiểm thử hộp đen với phương pháp kiểm thử giá trị biên để kiểm thử module A, ta viết stub trả giá trị biên để module A sử dụng: public double TicketPrice_Stub1(int old, boolean isCoupon, int numOfPerson, int day) { return 10000.0; } public double TicketPrice_Stub2(int old, boolean isCoupon, int numOfPerson, int day) { return 9999.0; } public double TicketPrice_Stub3(int old, boolean isCoupon, int numOfPerson, int day) { return 20000.0; } public double TicketPrice_Stub4(int old, boolean isCoupon, int numOfPerson, int day) { return 20001.0; } public double TicketPrice_Stub5(int old, boolean isCoupon, int numOfPerson, int day) { return 19999.0; } Với Stub: TicketPrice_Stub3(): public double TotalMoney(int old, boolean isCoupon, int numOfPerson, int day) { double p = TicketPrice_Stub3((old, isCoupon, numOfPerson, day); // * if (p > 10000 && p < 20000) // Lỗi p>=10000 p = p - 0.16 * p; else if (p > 20000) // Lỗi p>=20000 p = p - 0.2 * p; else p = p - 0; return p; } Kết kiểm thử cho hàm TotalMoney(): Testcase 10000 9999 20000 20001 19999 EO 8400 9999 16000 16000.8 16799.16 Result Fail (10000) Pass Fail (20000) Pass Pass II Chi n lược kiểm thử Botom up Trường hợp 1: C D hoàn thành, B chưa hoàn thành Dựa theo yêu cầu toán trên, giả sử module C module D hoàn thành, module B chưa hoàn thành Hiện cần kiểm thử tính đắn modules này: boolean checkday(int day) { if(day >= && day < 7) return true; else return false; } boolean isCoupon(boolean isCoupon, int numOfPerson) { if(isCoupon && numOfPerson < 20) return true; return false; } public double TicketPrice_Driver1(int old, boolean isCoupon, int numOfPerson, int day) { if(checkday(7) == true) return 1; if(checkday(8) == true) return 0; if(checkday(2) == true) return 1; if(checkday(1) == false) return 0; return 1; } Áp dụng phương pháp kiểm thử giá trị biên cho module này: Testcase {14, true, 20, 1} {14, true, 20, 2} {14, true, 20, 7} {14, true, 20, 8} EO Result 1 Pass Pass Fail Pass Áp dụng tương tự với Driver cho module isCoupon() Trường hợp B hoàn thành, A chưa hoàn thành Ta cần kiểm thử đắn module B public double TicketPrice(int old, boolean isCoupon, int numOfPerson, int day) { if (checkday(day)) { if (numOfPerson >= 20) { if (old >= 13) price = numOfPerson * 800; else { price = numOfPerson * 300; } } else { if (old >= 13) price = numOfPerson * 1200; else { price = numOfPerson * 800; } } if (isCoupon(isCoupon, numOfPerson)) { price -= price * 0.2; } return price; } return -1; } Testcase để kiểm thử hàm TicketPrice với độ phủ C2: Test path Input O EO Result 1-12 1-2-3-5-9-11 1-2-3-5-9-1011 1-2-3-6-9-11 1-2-3-6-9-1011 1-2-4-7-9-11 1-2-4-7-9-1011 1-2-4-8-9-11 1-2-4-8-9-1011 (10, true, 20, 1) (10, false, 15, 5) (10, true, 15, 5) -1 12000 9600 -1 12000 9000 Pass Pass Pass (20, false, 15, 5) (20, true, 15, 5) 12000 14400 12000 13500 Pass Fail (5, false, 25, 5) x 7500 x 7500 x Pass x (20, false, 25, 5) x 20000 x 20000 x Pass x Viết Driver để chạy module B (TicketPrice) public double TotalMoney_Driver1(int old, boolean isCoupon, int numOfPerson, int day) { return TicketPrice(10, true, 20, 1); } public double TotalMoney_Driver2(int old, boolean isCoupon, int numOfPerson, int day) { return TicketPrice(10, false, 15, 5); } public double TotalMoney_Driver3(int old, boolean isCoupon, int numOfPerson, int day) { return TicketPrice(10, true, 15, 5); } Tương tự cho Driver khác 10 ... phương pháp kiểm thử hộp đen với phương pháp kiểm thử giá trị biên để kiểm thử hàm TotalMoney Testcase {12, true, 20, 4} {13, true, 20, 4} {12, true, 19, 4} {13, true, 20, 4} EO 4800.0 108 00.0 12160.0... Fail (12160) Pass Fail Fail Fail Trường hợp A hoàn thành, B chưa hoàn thành Áp dụng chiến lược kiểm thử hộp đen với phương pháp kiểm thử giá trị biên để kiểm thử module A, ta viết stub trả giá trị... để kiểm thử hàm TicketPrice với độ phủ C2: Test path Input O EO Result 1-12 1-2-3-5-9-11 1-2-3-5-9 -101 1 1-2-3-6-9-11 1-2-3-6-9 -101 1 1-2-4-7-9-11 1-2-4-7-9 -101 1 1-2-4-8-9-11 1-2-4-8-9 -101 1 (10,

Ngày đăng: 21/12/2022, 15:58

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN

w