Testing and maintenance
แนะนำใหม่
19:05
รอบชีวิตการพัฒนาโปรแกรม
บั๊กเล็กๆ หากหลุดออกไปจนถึงเวอร์ชันReleased อาจต้องใช้เงินมหาศาลในการแก้ไข — มากกว่ามากที่จะจับมันได้ตั้งแต่ต้น นั่นคือเหตุผลที่เราไม่เพียงแค่มารอพิมพ์โค้ด เราทำตาม…
บรรยายภาษาอังกฤษ · สลับคำบรรยายภาษาอังกฤษและภาษาจีนได้
ในบทเรียนนี้
| English | ความหมาย |
|---|---|
| code/kəʊd/ | Instructions written in a programming language for a computer to follow. |
| 16-bit integer | A whole number stored using 16 binary digits. |
| conversion/kənˈvɜːʃn/ | The process of changing a value from one data type to another. |
| overflowed | Describes a value that was outside the range its storage could represent. |
| run-time error/rʌn taɪm ˈerə/ | ข้อผิดพลาดขณะทำงาน |
| routine/ruːˈtiːn/ | A set of instructions that performs a particular task within a program. |
| test data/test ˈdeɪtə/ | Data chosen to check whether a program works as expected. |
| testing/ˈtestɪŋ/ | Running a program with chosen inputs to check that it gives the expected outputs. |
| syntax error/ˈsɪntæks ˈerə/ | ข้อผิดพลาดทางไวยากรณ์ |
| keyword/ˈkiːwɜːd/ | A word with a fixed meaning in a programming language or pseudocode. |
| translation/trænˈsleɪʃn/ | Expressing the meaning of a message or text in another language. |
| array index | A whole number that identifies the position of an item in an array. |
| exception/ekˈsepʃn/ | An event that signals an error or unusual condition while a program runs. |
| logic error/ˈlɒdʒɪk ˈerə/ | ความผิดพลาดด้านตรรกะ |
| loop/luːp/ | A structure that repeats a sequence of instructions. |
| conditions/kənˈdɪʃnz/ | A requirement or circumstance that affects what happens or whether something is true. |
| tracing/ˈtreɪsɪŋ/ | The process of following a program step by step and recording variable values. |
| translator/trænˈsleɪtə/ | A program that changes code into a form a computer can execute. |
| dry run/draɪ rʌn/ | การรันแบบแห้ง |
| variable/ˈveərɪəbl/ | A quantity or named value that can change or take different values. |
| trace table/treɪs ˈteɪbl/ | A table recording variable values and outputs as an algorithm's steps are followed. |
| walkthrough/ˈwɔːkθruː/ | การตรวจสอบผ่าน |
| White-box testing/waɪt bɒks ˈtestɪŋ/ | Testing that uses the internal structure of code to design tests. |
| statement/ˈsteɪtmənt/ | A line of code that tells a program what to do. |
| branch/bræntʃ/ | A path of instructions chosen according to a condition or value. |
| Black-box testing/blæk bɒks ˈtestɪŋ/ | Testing that uses the specification to design tests without examining the code. |
| specification/ˌspesɪfɪˈkeɪʃn/ | A description of what a program must do and the requirements it must meet. |
| Integration testing/ˌɪntɪˈɡreɪʃn ˈtestɪŋ/ | Testing combined modules to check that they work together correctly. |
| modules/ˈmɒdjuːlz/ | Separately organised program components that perform defined tasks and communicate through interfaces. |
| interfaces | Points where modules connect and exchange data or commands. |
| stub/stʌb/ | สตั๊บ (Stub) |
| alpha testing/ˈælfə ˈtestɪŋ/ | การทดสอบอัลฟา |
| beta testing/ˈbiːtə ˈtestɪŋ/ | การทดสอบเบตา |
| Acceptance testing/əkˈseptəns ˈtestɪŋ/ | Testing by the customer against requirements to decide whether a product is suitable. |
| test strategy/test ˈstrætədʒi/ | กลยุทธ์การทดสอบ |
| test plan/test plæn/ | แผนการทดสอบ |
| expected output/ekˈspektɪd ˈaʊtpʊt/ | The result a test should produce if the program works correctly. |
| actual output | The result a program produces when a test is run. |
| expected result | |
| Normal data/ˈnɔːml ˈdeɪtə/ | Typical valid values inside the range, which should be accepted and processed correctly. |
| Abnormal data/əbˈnɔːml ˈdeɪtə/ | Values that should be rejected, out of range or the wrong type. |
| Extreme data/ekˈstriːm ˈdeɪtə/ | The smallest and largest values that a program should accept. |
| Boundary data/ˈbaʊndəri ˈdeɪtə/ | Values at and just outside the edges of the accepted range. |
| Corrective maintenance/kəˈrektɪv ˈmeɪntənəns/ | The process of fixing faults found in software after release. |
| Adaptive maintenance/əˈdæptɪv ˈmeɪntənəns/ | The process of changing software to keep it working in a changed environment. |
| operating system/ˈɒpəreɪtɪŋ ˈsɪstəm/ | System software that manages hardware resources and provides services for applications. |
| API/ˌeɪ piː ˈaɪ/ | A set of rules that allows one program to use another program's services. |
| Perfective maintenance/pəˈfektɪv ˈmeɪntənəns/ | The process of improving software that already works after its release. |
| algorithm/ˈælɡərɪθəm/ | A finite sequence of precise steps for solving a problem or carrying out a task. |
| data flow | The movement of data through the different parts of a program. |
| subroutine/ˈsʌbruːtiːn/ | A named set of instructions that performs a task when called. |
| caller/ˈkɔːlə/ | The program or module that asks another module to run. |
| parameter list | The ordered list of variables that receive values when a subroutine is called. |
| data structure/ˈdeɪtə ˈstrʌktʃə/ | A way of organising and storing data to support particular operations. |
| regression testing/rɪˈɡreʃn ˈtestɪŋ/ | การทดสอบย้อนกลับ |
สี่สิบเจ็ดวินาที
- ในวันที่ 4 มิถุนายน 1996 จรวด Ariane 5 ลำแรกถูกส่งขึ้นจากเฟรนช์โกลียา 37 วินาทีต่อมา มันเบี่ยงเบนเส้นทางและทำลายตัวเองNames of payloads worth $370 ล้าน
- สาเหตุมาจากรหัสเพียงบรรทัดเดียวที่ถูกนำกลับมาใช้จากเอเรียน 4 ซึ่งแปลงตัวเลขขนาด 64 บิตให้เป็นจำนวนเต็มขนาด 16 บิต เอเรียน 5 บินเร็วขึ้น ตัวเลขมีขนาดใหญ่ขึ้น และการแปลงนี้เกิดการล้น (overflow): ความผิดพลาดในช่วงรันไทม์ (run-time error) ในฟังก์ชันที่ไม่จำเป็นแม้หลังยกตัว
- โค้ดนี้ไม่เคยถูกทดสอบกับข้อมูลการบินของเอเรียน 5 ไม่มีใครเลือกข้อมูลทดสอบที่ขอบเขตสูงสุดของช่วงบินจรวดลำใหม่
- บทเรียนนี้คือสามประเภทของ error,วิธีการ testing,วิธีเลือก test data,และวิธีรักษา program ให้มีชีวิตต่อหลัง release

สามประเภทของความผิดพลาด
- ความผิดพลาดด้านไวยากรณ์ (syntax error) ทำลายกฎของภาษา: การขาดวงเล็บ, คำสำคัญพิมพ์ผิด พบได้ระหว่างการแปล (translation), ดังนั้นโปรแกรมจะไม่ทำงานจนกว่าจะแก้ไข
- A run-time error happens while the program runs: division by zero, a file that does not exist, an array index out of range. The program crashes or raises an exception; the fix is a check before the risky operation.
- ความผิดพลาดด้านตรรกะ (logic error) ทำให้โปรแกรมสามารถทำงานและสร้าง ผลลัพธ์ที่ผิด:
+สำหรับ-, ลูปที่ผิดเพี้ยนไปหนึ่งรอบ, เงื่อนไขในลำดับที่ผิด ไม่มีการเตือนอะไร; เพียงการทดสอบและการติดตาม (tracing) เท่านั้นที่จะเผยให้เห็น

พบระหว่างการแปล, พบในช่วงรันไทม์, พบเฉพาะในผลลัพธ์
Match each kind of error to how it shows up.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Syntax = caught at translation; logic = wrong output; run-time = crash while running.
ตัวอย่างวิธีทำ: หาและแก้ไขความผิดพลาด
Total ← 0
FOR i ← 1 TO Count
Total ← Total + Marks[i]
NEXT i
Average ← Total / Count
IF Average > 50 THEN
OUTPUT "Pass"
- ด้านไวยากรณ์:
IFไม่มีENDIF. ตัวแปลปฏิเสธ ด้านรันไทม์: หากCountเป็น 0 การหารจะล้มเหลว; ป้องกันด้วยIF Count > 0 THEN. ด้านตรรกะ: หากคะแนนสอบเป็น 50 ขึ้นไป,> 50จะตัดสินนักเรียนที่คะแนน 50 พอดีว่าไม่ผ่าน; ควรจะเป็น>= 50** - ชี้ชื่อประเภท,อธิบายเหตุผลว่าเป็น type นั้น,และให้ correction.สามส่วน,สามคะแนน
A program divides a total by the number of entries and crashes when the input file is empty. This is a:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Division by zero happens while the program runs and stops it. A guard such as IF Count > 0 fixes it.
วิธีการทดสอบ: อ่านโค้ด
- Dry run ติดตาม code บนกระดาษ,เขียนค่าของตัวแปรแต่ละตัวใน trace table หลังแต่ละบรรทัด
- Walkthrough คือ team review: programmer อธิบาย code บรรทัดต่อบรรทัดขณะที่เพื่อนร่วมงานมองหาข้อผิดพลาด
- White-box testing ออกแบบ tests จากโครงสร้างภายในของ code,เพื่อให้ทุก statement,branch และ loop ถูก exercised. Black-box testing ออกแบบ tests จาก specification เท่านั้น:ป้อน inputs,เปรียบเทียบ outputs กับสิ่งที่คาดหวัง,โดยไม่ต้องมองที่ code

*มองเข้ามาภายนอก, หรือมองเข้าไปภายในเพื่อตรวจสอบทุกเส้นทาง
Designing test cases from the specification only (inputs and expected outputs), ignoring the code inside, is called ______-box testing.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Black-box tests from the spec; white-box uses the code's internal structure to cover statements and branches.
วิธีการทดสอบ: การประกอบและการปล่อย
- การทดสอบแบบบูรณาการ (Integration testing) รวมโมดูลที่ทดสอบแยกต่างหากและทดสอบอินเทอร์เฟซระหว่างกัน สตับ (stub) แทนที่โมดูลที่ยังไม่เขียน, ส่งคืนค่าคงที่เพื่อให้ส่วนอื่นๆ สามารถทดสอบแบบลงสู่ระดับล่างได้
- การทดสอบแบบอัลฟา (Alpha testing) α ทำภายในองค์กรโดยนักพัฒนา ก่อนการปล่อย การทดสอบแบบเบตา (Beta testing) β ให้กลุ่มผู้ใช้จริงจำนวนจำกัดใช้งานโปรแกรมในสภาพแวดล้อมของตนเอง
- การทดสอบการยอมรับ (Acceptance testing) ทำโดยลูกค้า ตามข้อกำหนด, เพื่อตัดสินใจว่าผลิตภัณฑ์พร้อมใช้งานหรือไม่
Software process lab
Classify development examples by the stage or tool they belong to.
ตัวอย่างวิธีทำ: วิธีไหนสำหรับสถานการณ์ไหน
- โมดูลรายงานเสร็จแล้วแต่โมดูลฐานข้อมูลที่มันเรียกยังไม่มี: ทดสอบด้วย สตับ ที่ส่งคืนข้อมูลคงที่
- สองโมดูลผ่านการทดสอบของตัวเองแต่ล้มเหลวเมื่อผลลัพธ์ของโมดูลหนึ่งป้อนให้โมดูลอีก: การทดสอบแบบบูรณาการ ของอินเทอร์เฟซ
- ซอฟต์แวร์พร้อมใช้งานแล้ว; บริษัทต้องการให้พบข้อผิดพลาดในสภาวะจริงก่อนการปล่อยตัวจริง: beta testing โดยกลุ่มผู้ใช้จำนวนจำกัด
- ลูกค้าตัดสินใจว่าจะชำระเงินหรือไม่: acceptance testing เทียบกับข้อกำหนดที่ตกลงไว้ ให้ชื่อวิธีนี้ และ อธิบายวัตถุประสงค์ของมัน
Match each situation to the testing method it needs.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Stub for a missing part, beta for real users, acceptance for the customer, integration for the joins.
กลยุทธ์การทดสอบและแผนการทดสอบ
- Test strategy คือแนวทางระดับสูง: จะมีการทดสอบประเภทใดบ้าง, ทำโดยใคร, เมื่อไหร่, และต้องผ่านอะไรก่อนเข้าสู่ขั้นตอนถัดไป
- Test plan คือรายการละเอียดของการทดสอบ สำหรับแต่ละข้อ: วัตถุประสงค์, ข้อมูลเข้า, expected output, และคอลัมน์สำหรับ actual output เมื่อรันการทดสอบ
- Test ที่ไม่มี expected result ไม่ใช่ test.มันเพียงแสดงว่า program ทำอะไร,แต่ไม่บอกว่าสิ่งนั้นถูกต้องหรือไม่
A test plan lists, for each test, the input data and the expected output.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Purpose, input, expected output and a column for the actual output. The strategy is the high-level approach; the plan is the detailed list.
การเลือกข้อมูลทดสอบ
- Normal data: ค่าปกติที่ถูกต้องภายในช่วงที่ยอมรับได้ ซึ่งควรได้รับการยอมรับและประมวลผลอย่างถูกต้อง
- Abnormal data: values ที่ควร rejected, out of range หรือผิด type
- Extreme data: ค่าที่ใหญ่ที่สุดและเล็กที่สุดที่ยังคง รับได้, ที่ขอบเขตของช่วง Boundary data: คู่ที่ข้ามแต่ละขอบเขต ได้แก่ ค่า extreme ที่รับได้และค่าที่ถูกปฏิเสธที่อยู่นอกขอบเขตเล็กน้อย ซึ่งที่นั่นซ่อนอยู่ความผิดพลาดแบบ off-by-one

ด้านใน, ด้านนอก, และตรงบนเส้น
For a field that accepts marks 0–100, which are the boundary test values?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Boundary data sits at the edges of the valid range (and just outside) — where off-by-one errors hide.
ตัวอย่างงาน: ข้อมูลทดสอบสำหรับคะแนนตั้งแต่ 0 ถึง 100
| Kind | Data | Expected result |
|---|---|---|
| normal | 50, 75 |
accepted and processed |
| abnormal | -10, 200, "abc" |
rejected: out of range or wrong type |
| extreme | 0, 100 |
accepted: the smallest and largest valid values |
| boundary | -1 and 0, 100 and 101 |
-1 rejected, 0 accepted; 100 accepted, 101 rejected |
- ทุกบรรทัดต้องมี ผลลัพธ์ที่คาดหวัง; ตารางที่มีเพียงอินพุตเพียงอย่างเดียวจะได้อะไรได้ครึ่งหนึ่ง ค่าสุดขั้วคือ ที่ยอมรับ:
-1เป็นค่าขอบเขต ไม่ใช่ค่าสุดขั้ว

A field accepts marks from 0 to 100. Which values are extreme test data? Select ทั้งหมด that apply.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Extreme values are the smallest and largest still accepted. -1 is rejected, so it is boundary or abnormal; 50 is normal.
การบำรุงรักษา
- ส่วนใหญ่ของค่าใช้จ่ายตลอดอายุการใช้งานของโปรแกรมถูกใช้หลังการปล่อยตัว Corrective maintenance แก้ไขข้อผิดพลาดที่พบขณะใช้งาน
- Adaptive maintenance ทำให้โปรแกรมทำงานต่อได้ในสภาพแวดล้อมที่เปลี่ยนแปลง: ระบบปฏิบัติการใหม่, API ใหม่, การเปลี่ยนแปลงทางกฎหมาย
- Perfective maintenance ปรับปรุงโปรแกรมที่ทำงานอยู่แล้ว: ประสิทธิภาพเร็วขึ้น, ฟังก์ชันใหม่ที่ผู้ใช้ร้องขอ โปรแกรมอาจต้องการทั้งสามชนิดตลอดอายุการใช้งาน

แก้ไขให้, รักษาให้ทำงานต่อ, ทำให้ดีขึ้น
Corrective maintenance fixes faults, perfective maintenance improves features, and adaptive maintenance keeps the software working in a changed environment.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Three maintenance types: corrective (fix bugs), perfective (enhance), adaptive (new OS/hardware/rules).
A payroll program is changed because the tax law changed. Which kind of maintenance is this?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
The program was not faulty and is not being improved; its environment changed. That is adaptive maintenance.
การแก้ไขโปรแกรมที่มีอยู่
- อ่านโค้ดเดิมจนเข้าใจอัลกอริทึมและการไหลของข้อมูล หาจุดที่ต้องการแก้ไข: subroutineไหน, บรรทัดไหน
- ทำการเปลี่ยนแปลงให้ น้อยที่สุด; อย่าเขียนโค้ดที่ทำงานอยู่แล้วใหม่ อัปเดตทุกส่วนที่เกี่ยวข้อง: ผู้เรียกพารามิเตอร์ที่เปลี่ยน, routine ที่ใช้โครงสร้างข้อมูลที่เปลี่ยน
- ทดสอบพฤติกรรมใหม่ และ เก่า: regression testing ตรวจสอบว่าสิ่งที่เคยทำงานไม่ได้เสียไป Then document the change.
After changing a program, regression testing checks that:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Regression testing re-runs old tests to confirm existing behaviour still works after a change.
Put the steps of amending an existing program in order.
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Understand, locate, change small, propagate, test everything, record. Skipping the regression test is how a fix breaks something else.
การ์ดนี้ได้รับการแก้ไขแล้ว จึงแสดงเป็นภาษาอังกฤษจนกว่าคำแปลจะได้รับการอัปเดต
Marks that slip away
- Extreme is accepted; abnormal is rejected.
0and100are extreme;-1and101are boundary values on the rejected side. - A logic error can produce wrong output or lead to a run-time error, such as an out-of-range array access.
- Alpha is in-house; beta is real users outside. A stub replaces a missing module; it is not a test method for finished code.
- A test plan row without an expected output 预期输出 earns nothing. Regression testing follows every change.
คุณเข้าใจแล้ว
- syntax errors หยุดการแปล · run-time errors ทำให้โปรแกรมที่กำลังทำงาน crash · logic errors ทำงานและให้ผลลัพธ์ผิด, พบได้จากการทดสอบเท่านั้น
- methods: dry run, walkthrough, white-box (จากโค้ด), black-box (จากสเปค), integration (interfaces, กับ stubs สำหรับโมดูลที่ขาด), alpha (ภายในองค์กร), beta (ผู้ใช้จริง), acceptance (ลูกค้า)
- test data: normal รับได้, abnormal ถูกปฏิเสธ, extreme เป็นขอบเขตที่ยอมรับได้, boundary ทั้งสองข้างของแต่ละขอบเขต; การทดสอบทุกครั้งมีผลลัพธ์ที่คาดหวัง
- maintenance: corrective แก้ไข, adaptive ตามทันสภาพแวดล้อม, perfective ปรับปรุง; แก้ไขเล็กน้อย, อัปเดตผู้เรียก, regression test
เกิดปัญหาอะไรขึ้น? เฉพาะทีมเว็บไซต์เท่านั้นที่เห็นข้อมูลนี้