UML中一种功能测试用例设计模式
作者:廖光明 (liaogm2002@hotmail.com)
1.1 目的
统一项目系统测试阶段测试用例设计方法,达到测试用例与需求Use Case对应,路径覆盖较好、维护方便,测试脚本与数据分离、偶合性低,场景清晰的目的。
1.2 术语说明
按照UML规则和RUP过程,引入如下术语:
The specification (usually formal) of a set of test inputs, execution conditions, and expected results, identified for the purpose of making an evaluation of some particular aspect of a target test item.
测试用例是为特定测试目标开发的测试输入、执行条件和预期结果的集合。这些特定目标可以是:验证一个特定的程序路径或核实是否符合特定需求。
A model that describes a system's functional requirements in terms of use cases.
A description of system behavior, in terms of sequences of actions.
The specification of an executable statement that forms an abstraction of a computational procedure. An action typically results in a change in the state of the system, and can be realized by sending a message to an object or modifying a link or a value of an attribute.
Use Case instance
Use Case instance is the performance of a sequence of actions being specified in a Use Case. A use-case instance is a specific "end-to-end" concrete path through a Use Case—actors are replaced by specific persons (actor instances), specific values and responses are given and only a single path is taken through one or more possible flows of the Use Case. See also: scenario
A specific sequence of actions that illustrates behaviors. A scenario may be used to illustrate an interaction or the execution of one or more use-case instances.
A collection of step-by-step instructions that realize a test, enabling its execution. Test scripts may take the form of either documented textual instructions that are executed manually or computer readable instructions that enable automated test execution.
A package-like artifact used to group collections of test scripts, both to sequence the execution of the tests and to provide a useful and related set of Test Log information from which Test Results can be determined..Synonyms: test driver.
2 适用范围
适用于项目功能测试Test Case的设计。
由于测试用例的复杂性,需要特殊设计的Case,可不受本规范限制。
3 测试用例设计基本规则
3.1 测试用例组成
按照测试用例的定义,测试用例包括输入、执行步骤和期望结果三个基本组成部分。
3.2 测试脚本与测试数据分离
按照测试脚本(Test Script)的定义,测试脚本包括两种类型:
l 用于指导手工测试执行的操作步骤文字描述
l 用于自动测试能被计算机识别的操作步骤代码。
测试程序就是测试操作过程,一个测试程序可输入不同特性的数据,如:典型数据值、边界值、异常值等。因此,为提高脚本使用效率,测试程序与测试数据分离管理。
3.3 测试用例需求覆盖性设计
3.3.1 把 Use-Case model 分解为 Use Case
按照UML的定义:Use-Case model 通过Use Case来描述系统的功能需求。为使Use-Case model可测试,可把Use-Case model分解为Use Case,形成具有明确输入,输出和action组合的功能单元。
3.3.2 从场景生成测试用例
用于功能性测试的测试用例来源于测试目标的Use Case。Use Case中不同的路径确定一个Use Case instance既一个场景,每个场景必需编制测试用例。通过测试用例与Use Case instance的对应来尽可能覆盖测试目标的需求。对应关系如下所示:
3.3.2 场景由分枝构成
根据定义,场景包括一个或以上的分枝;每个场景包括起点、终点和Use Case中某些特定分枝的组合(路径)。生成每个场景的测试用例是通过确定某个特定条件来完成的,这个特定条件将导致特定用例场景的执行。
Use Case的与分枝关系图如下:
因此,根据Use Case中不同分枝(即不同备选流