Test case-equivalence class division method

1. Introduction to the method

1. Definition

It is to divide all possible input data, that is, the input domain of the program into several parts (subsets), and then select a few representative data from each subset as test cases. This method is an important and commonly used black-box test case design method.

2. Divide the equivalence class:

An equivalence class is a subset of an input domain. In this subset, each input data is equivalent to revealing errors in the program, and it is reasonable to assume that testing a representative value of an equivalence class is equivalent to testing other values ​​of this class. The input data is reasonably divided into several equivalence classes, and a small amount of representative test data can be used to obtain better test results by taking one data in each equivalence class as the input condition of the test. There are two different cases of equivalence class division: valid equivalence classes and invalid equivalence classes.

1) Effective equivalence class

A set of input data that is reasonable and meaningful for the specification of a program. Use valid equivalence classes to verify that a program implements the functions and performance specified in the specification.

2) Invalid equivalence class

Contrary to the definition of efficient equivalence classes. An invalid equivalence class is a set of input data whose specification for a program is unreasonable or meaningless. For a specific problem, there should be at least one invalid equivalence class, and there may be more than one.

When designing test cases, consider both equivalence classes. Because the software must not only receive reasonable data, but also be able to withstand unexpected tests, such tests can ensure that the software has higher reliability.

3. Criteria for dividing equivalence classes:

1) Complete testing to avoid redundancy;

2) It is important to divide the equivalence class: the division of the set is divided into a set of subsets that do not intersect with each other, and the union of the subsets is the entire set;

3) and is the entire set: completeness;

4) Subsets are mutually disjoint: guarantee a form of non-redundancy;

5) Identify (select) a test case in the same class. In the same equivalence class, the processing is often the same, and the same processing is mapped to the "same execution path".

4. Methods of dividing equivalence classes

1) When the input condition specifies the value range or the number of values, one valid equivalence class and two invalid equivalence classes can be established. For example: the input value is the student's grade, the range is 0~100;

2) In the case where the input condition specifies the set of input values ​​or specifies the "must be" condition, a valid equivalence class and an invalid equivalence class can be established;

3) When the input condition is a Boolean quantity, a valid equivalence class and an invalid equivalence class can be determined.

4)在规定了输入数据的一组值(假定n个),并且程序要对每一个输入值分别处理的情况下,可确立n个有效等价类和一个无效等价类。

例:输入条件说明学历可为:专科、本科、硕士、博士四种之一,则分别取这四种这四个值作为四个有效等价类,另外把四种学历之外的任何学历作为无效等价类。

5)在规定了输入数据必须遵守的规则的情况下,可确立一个有效等价类(符合规则)和若干个无效等价类(从不同角度违反规则);

6)在确知已划分的等价类中各元素在程序处理中的方式不同的情况下,则应再将该等价类进一步的划分为更小的等价类。

5.设计测试用例

在确立了等价类后,可建立等价类表,列出所有划分出的等价类输入条件:有效等价类、无效等价类,然后从划分出的等价类中按以下三个原则设计测试用例:

1)为每一个等价类规定一个唯一的编号;

2)设计一个新的测试用例,使其尽可能多地覆盖尚未被覆盖地有效等价类,重复这一步,直到所有的有效等价类都被覆盖为止;

3)设计一个新的测试用例,使其仅覆盖一个尚未被覆盖的无效等价类,重复这一步,直到所有的无效等价类都被覆盖为止。

二.实战演习

1.某程序规定:"输入三个整数 a 、 b 、 c 分别作为三边的边长构成三角形。通过程序判定所构成的三角形的类型,当此三角形为一般三角形、等腰三角形及等边三角形时,分别作计算 … "。用等价类划分方法为该程序进行测试用例设计。(三角形问题的复杂之处在于输入与输出之间的关系比较复杂。)

分析题目中给出和隐含的对输入条件的要求:

(1)整数 (2)三个数 (3)非零数 (4)正数

(5)两边之和大于第三边 (6)等腰 (7)等边

如果 a 、 b 、 c 满足条件( 1 ) ~ ( 4 ),则输出下列四种情况之一:

1)如果不满足条件(5),则程序输出为 " 非三角形 " 。

2)如果三条边相等即满足条件(7),则程序输出为 " 等边三角形 " 。

3)如果只有两条边相等、即满足条件(6),则程序输出为 " 等腰三角形 " 。

4)如果三条边都不相等,则程序输出为 " 一般三角形 " 。

列出等价类表并编号

覆盖有效等价类的测试用例:

a b c 覆盖等价类号码

3 4 5 (1)--(7)

4 4 5 (1)--(7),(8)

4 5 5 (1)--(7),(9)

5 4 5 (1)--(7),(10)

4 4 4 (1)--(7),(11)

覆盖无效等价类的测试用例:

2.设有一个档案管理系统,要求用户输入以年月表示的日期。假设日期限定在1990年1月~2049年12月,并规定日期由6位数字字符组成,前4位表示年,后2位表示月。现用等价类划分法设计测试用例,来测试程序的"日期检查功能"。

1)划分等价类并编号,下表等价类划分的结果

1)划分等价类并编号,下表等价类划分的结果

输入等价类

有效等价类

无效等价类

  日期的类型及长度

  ①6位数字字符

②有非数字字符

③少于6位数字字符

④多于6位数字字符

 年份范围

  ⑤在1990~2049之间

⑥小于1990
⑦大于2049

 月份范围

  ⑧在01~12之间

⑨等于00

⑩大于12

2)设计测试用例,以便覆盖所有的有效等价类在表中列出了3个有效等价类,编号分别为①、⑤、⑧,设计的测试用例如下:

测试数据 期望结果 覆盖的有效等价类

200211 输入有效 ①、⑤、⑧

3)为每一个无效等价类设计一个测试用例,设计结果如下:

测试数据 期望结果 覆盖的无效等价类

95June 无效输入 ②

20036 无效输入③

2001006无效输入 ④

198912 无效输入 ⑥

200401 无效输入 ⑦

200100 无效输入 ⑨

200113 无效输入 ⑩

3.NextDate 函数包含三个变量:month 、 day 和 year ,函数的输出为输入日期后一天的日期。 例如,输入为 2006年3月 7日,则函数的输出为 2006年3月8日 。要求输入变量 month 、 day 和 year 均为整数值,并且满足下列条件:

①1≤month≤12

②1≤day≤31

③1920≤year≤2050

1)有效等价类为:

M1={月份:1≤月份≤12}

D1={日期:1≤日期≤31}

Y1={年:1812≤年≤2012}

2)若条件 ① ~ ③中任何一个条件失效,则 NextDate 函数都会产生一个输出,指明相应的变量超出取值范围,比如 "month 的值不在 1-12 范围当中 " 。显然还存在着大量的 year 、 month 、 day 的无效组合, NextDate 函数将这些组合作统一的输出: " 无效输入日期 " 。其无效等价类为:

M2={月份:月份<1}

M3={月份:月份>12}

D2={日期:日期<1}

D3={日期:日期>31}

Y2={年:年<1812}

Y3={年:年>2012}

弱一般等价类测试用例

月份 日期 年 预期输出

6 15 1912 1912年6月16日

强一般等价类测试用例同弱一般等价类测试用例

注:弱--有单缺陷假设;健壮--考虑了无效值

(一)弱健壮等价类测

用例ID 月份 日期 年 预期输出

WR1 6 15 1912 1912年6月16日

WR2 -1 15 1912 月份不在1~12中

WR3 13 15 1912 月份不在1~12中

WR4 6 -1 1912 日期不在1~31中

WR5 6 32 1912 日期不在1~31中

WR6 6 15 1811 年份不在1812~2012中

WR7 6 15 2013 年份不在1812~2012中

(二)强健壮等价类测试

用例ID 月份 日期 年 预期输出

SR1 -1 15 1912 月份不在1~12中

SR2 6 -1 1912 日期不在1~31中

SR3 6 15 1811 年份不在1812~2012中

SR4 -1 -11912 两个无效一个有效

SR5 6 -1 1811 两个无效一个有效

SR6 -1 15 1811 两个无效一个有效

SR7 -1 -11811 三个无效
 

4.佣金问题等价类测试用例,它是根据佣金函数的输出值域定义等价类,来改进测试用例集合。

输出销售额≤1000元 佣金10%

  1000<销售额≤1800 佣金=100+(销售额-1000)*15%

  销售额>1800 佣金=220+(销售额-1800)*20%

  测试用例 枪机(45) 枪托(30) 枪管(25) 销售额 佣金

  

1 5 5 5 500 50

2 15 15 15 1500 175

3 25 25 25 2500 360

根据输出域选择输入值,使落在输出域等价类内,可以结合弱健壮测试用例结合。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326843279&siteId=291194637