| English | 释义 | 拼音 |
|---|---|---|
| run-time error/rʌn taɪm ˈerə/ | 运行时错误 | yùn xíng shí cuò wù |
| syntax error/ˈsɪntæks ˈerə/ | 语法错误 | yǔ fǎ cuò wù |
| logic error/ˈlɒdʒɪk ˈerə/ | 逻辑错误 | luó jí cuò wù |
| dry run/draɪ rʌn/ | 手工跟踪 | shǒu gōng gēn zōng |
| walkthrough/ˈwɔːkθruː/ | 走查 | zǒu chá |
| white-box testing/waɪt bɒks ˈtestɪŋ/ | 白盒测试 | bái hé cè shì |
| black-box testing/blæk bɒks ˈtestɪŋ/ | 黑盒测试 | hēi hé cè shì |
| integration testing/ˌɪntɪˈɡreɪʃn ˈtestɪŋ/ | 集成测试 | jí chéng cè shì |
| stub/stʌb/ | 桩 | zhuāng |
| alpha testing/ˈælfə ˈtestɪŋ/ | α测试 | α cè shì |
| beta testing/ˈbiːtə ˈtestɪŋ/ | β测试 | β cè shì |
| acceptance testing/əkˈseptəns ˈtestɪŋ/ | 验收测试 | yàn shōu cè shì |
| test strategy/test ˈstrætədʒi/ | 测试策略 | cè shì cè lüè |
| test plan/test plæn/ | 测试计划 | cè shì jì huà |
| normal data/ˈnɔːml ˈdeɪtə/ | 正常数据 | zhèng cháng shù jù |
| abnormal data/əbˈnɔːml ˈdeɪtə/ | 异常数据 | yì cháng shù jù |
| extreme data/ekˈstriːm ˈdeɪtə/ | 极端数据 | jí duān shù jù |
| boundary data/ˈbaʊndəri ˈdeɪtə/ | 边界数据 | biān jiè shù jù |
| corrective maintenance/kəˈrektɪv ˈmeɪntənəns/ | 纠正性维护 | jiū zhèng xìng wéi hù |
| adaptive maintenance/əˈdæptɪv ˈmeɪntənəns/ | 适应性维护 | shì yìng xìng wéi hù |
| perfective maintenance/pəˈfektɪv ˈmeɪntənəns/ | 完善性维护 | wán shàn xìng wéi hù |
| regression testing/rɪˈɡreʃn ˈtestɪŋ/ | 回归测试 | huí guī cè shì |
三十七秒
- 1996 年 6 月 4 日,第一枚阿丽亚娜 5 号火箭从法属圭亚那升空。三十七秒后它偏离航向并自毁。载荷是四颗价值 3.7 亿美元的卫星。
- 原因是从阿丽亚娜 4 号沿用的一行代码,它把一个 64 位数转换成 16 位整数。阿丽亚娜 5 号飞得更快,数字更大,转换溢出了:一个运行时错误(run-time error),而且出在升空后根本不再需要的例程里。
- 这段代码从未用阿丽亚娜 5 号的飞行数据测试过。没有人在新火箭范围的极端处选过测试数据。
- 这一课讲三种错误、测试方法、怎样选择测试数据,以及程序发布后怎样维持生命。
三种错误
- 语法错误(syntax error)违反语言的语法:缺少括号、关键字拼错。它在翻译时被发现,所以程序修好之前无法运行。
- 运行时错误在程序运行时发生:除以零、文件不存在、数组索引越界。程序崩溃或抛出异常;修法是在危险操作前加检查。
- 逻辑错误(logic error)让程序运行并产生错误的结果:
+写成-、差一的循环、条件顺序错误。没有任何东西标记它;只有测试和跟踪能揭示它。

翻译时发现,运行时发现,只在输出里发现
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。 - 说出类型,说明为什么是这种类型,给出纠正。三部分,三分。
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)在纸上追踪代码,在每一行之后把每个变量的值写进跟踪表。
- 走查(walkthrough)是团队评审:程序员逐行解释代码,同事们寻找错误。
- 白盒测试(white-box testing)根据代码的内部结构设计测试,让每条语句、每个分支和循环都被执行。黑盒测试(black-box testing)只根据规格说明设计测试:输入数据,把输出与期望比较,不看代码。

从外面往里看,或从里面看每条路径
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)由客户对照需求进行,决定产品是否符合用途。
软件过程实验
Classify development examples by the stage or tool they belong to.
例题:哪种情形用哪种方法
- 报表模块已完成,但它调用的数据库模块还不存在:用返回固定数据的桩测试它。
- 两个模块各自通过测试,但一个的输出送入另一个时失败:对接口做集成测试。
- 软件已完成;公司想在正式发布前在真实条件下发现故障:由一小群用户做β测试。
- 客户决定是否付款:对照约定需求的验收测试。既要说出方法也要说它的用途。
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)是详细的测试清单。每一项:目的、输入数据、期望输出,以及运行测试时填写实际输出的一列。
- 没有期望结果的测试不是测试。它只显示程序做了什么,不显示那是否正确。
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):应该被拒绝的值,超出范围或类型错误。
- 极端数据(extreme data):仍被接受的最大和最小值,在范围的边缘。边界数据(boundary data):跨在每条边两侧的一对——被接受的极端值和紧邻其外被拒绝的值——差一错误藏在那里。

里面、外面,和正好压在线上
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 分数的测试数据
| 类型 | 数据 | 期望结果 |
|---|---|---|
| 正常 | 50、75 |
接受并处理 |
| 异常 | -10、200、"abc" |
拒绝:超出范围或类型错误 |
| 极端 | 0、100 |
接受:最小和最大的有效值 |
| 边界 | -1 和 0,100 和 101 |
-1 拒绝,0 接受;100 接受,101 拒绝 |
- 每一行都需要期望结果;只有输入的表格得一半分。极端值是被接受的:
-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.
修改现有程序
- 阅读现有代码,直到理解算法和数据流。找出改动属于哪里:哪个子程序、哪几行。
- 把改动做到尽可能小;不要重写能用的代码。更新每个相关部分:参数列表改变后的每个调用者,数据结构改变后使用它的每个例程。
- 既测试新行为也测试旧行为:回归测试(regression testing)检查原来能用的没有被弄坏。然后记录改动。
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.
容易丢掉的分
- 极端是被接受的;异常是被拒绝的。
0和100是极端;-1和101是拒绝一侧的边界值。 - 逻辑错误不会让程序崩溃。崩溃了,那就是运行时错误。
- α在内部;β是外部的真实用户。桩代替缺失的模块;它不是对已完成代码的测试方法。
- 没有期望输出的测试计划行不得分。每次改动之后都要回归测试。
你掌握了
- 语法错误阻止翻译 · 运行时错误让运行中的程序崩溃 · 逻辑错误运行但输出错误,只有测试才能发现
- 方法:手工跟踪、走查、白盒(从代码)、黑盒(从规格说明)、集成(接口,用桩代替缺失模块)、α(内部)、β(真实用户)、验收(客户)
- 测试数据:正常被接受、异常被拒绝、极端是被接受的边缘、边界在每条边的两侧;每个测试都有期望结果
- 维护:纠正性修复、适应性跟上环境、完善性改进;小改、更新调用者、回归测试