Several common design methods of test cases

http://www.51testing.com/html/30/n-3719130.html

reprint

Common design methods of test cases include: equivalence class division method, boundary value analysis method, wrong speculation method, decision table method, and orthogonal experiment method.
   1. Equivalence class division method
  As the name implies, equivalence class division is to divide the test range into several disjoint subsets, their union is the complete set, and several representative values ​​are selected from each subset as test cases.
  For example, we want to test whether a user name is legal, the user name is defined as: 8-digit characters.
  We can start by dividing subsets: empty username, 1-7 digits, 8 digits, 9 or more digits, non-numeric.
Then select several representative values ​​from   each subset :
  Empty username: ""       (invalid equivalence class instance, meaningless and unreasonable input for software specification)
  1-7 digits: "234"        (invalid equivalence class instance)
  8-digit number: "00000000"     (a valid equivalence class instance that can verify whether the program implements the functions and performance specified in the specification)
  9 or more digits: "1234567890"     (invalid equivalence class instance)
  Not a number: "abc&!!!"                 (invalid equivalence class instance)
  There are 5 of them, which are the test cases selected by the equivalence class division. In fact, for the subset of 1-7 digits, there is no essential difference between choosing "234" and "11111".
  The division of equivalence classes, the most critical is the division of subsets. In fact, non-numbers can continue to be divided into subsets: letters, special characters.
  To what extent should the division be appropriate? I have asked a friend who does a test, and his opinion is to see how much resources and time you have, and whether it is worth it.
  I agree with this, after all, no matter how you test, there will always be undiscovered defects, so solve the problems that are easy to find first.
   2. Boundary value analysis method
  Long-term test work experience tells us that a large number of errors occur on the boundary of the input or output range, rather than inside the input and output range. Therefore, by designing test cases for various edge cases, more errors can be detected. The selected test case should select a value that is exactly equal to, just greater than, and just less than the boundary. For example, for the value in the interval min, max, the test case can be recorded as min, min+, max, max-.
  For example, assuming that X is an integer, 10≤X≤100, then the boundary values ​​that X should take in the test are: 10, 11, 99, 100.
  Note: The above is only about the boundary value. If it is a complete test, in addition to the boundary value, a normal value is required, that is, any value between 12-98.
   3. Miscalculation
  Error speculation refers to: when testing a program, people can infer various errors that may exist in the program based on experience or intuition, so as to write a method for testing these errors in a targeted manner.
  This method does not have a fixed form, it relies on experience and intuition, and many times, we use it unknowingly.
   4. Judgment table method
  Also known as strategy table, testing based on strategy table is the most rigorous testing method in functional testing. This method is suitable for scenarios with complex logical judgments. The results are obtained through exhaustive conditions, and the results are optimized and merged to obtain a clear judgment strategy table.
  For example, a company's criteria for classifying customers are as follows:
  If the customer orders more than 1,000 yuan each time (including 1,000 yuan), and the reputation is good, the order will be marked with "priority";
  信誉不好,但是老客户的,订单设“优先”标志;
  信誉不好,但是新客户的,订单设“正常”标志;
  每次订货额在 1000元以下,订单设“正常”标志。
  绘制的决策表如下:
  此表分两大行,两大列,分别用不同的颜色区别。
  浅蓝:列出所有条件(或称为输入)
  浅灰:列出所有结果(或称为输出,行动或决策)
  浅黄:穷举所有条件的组合
  浅绿:根据每一列的条件,判断出结果
  因为穷举了所有条件,所以可以说这个判断是100%正确的。下一步是对这个表进行合并优化。
   例如,从编号为1,2的列可以看出,顾客订单>=1000,信誉好,不管是新顾客还是老顾客,都设为优先,于是上面的表合并整理后,得到下表
  这样,我们就可以得到更清晰的逻辑判断,也可以更好的协助我们编写测试用例。而决策表,对于开发人员来说一样有用。
  从上面的表格,我们就可以写出更简洁的判断语句。
   五.正交实验法
  用语言描述正交实验法会很抽象难懂,简单说,就是在各因素互相独立的情况下,设计出一种特殊的表格,找出能以少数替代全面的测试用例。
  其中,上面所说的特殊表格就是正交表,是按照一定规则生成的表。
  虽然说是特殊的表格,实际表现形式跟一般的表格没有什么区别,正交表的主要特征是,“均匀分布,整齐划一”,正是因为“均匀”的,所以才能以少数代替全部。
  例如:
  某所大学通信系共2个班级,刚考完某一门课程,想通过“性别”、“班级”和“成绩”这三个查询条件对通信系这门课程的成绩分布,男女比例或班级比例进行人员查询。
  按照传统的方式,我们将会穷举所有的组合,来编写测试用例,组合个数是2*2*2=8。
  排列组合参见下表
  当组合条件不多的时候,穷举暂时没问题,但是,一旦条件多了,组合个数就会以指数形式增长。
  这个时候,就要用到正交表了,通过选出有代表性的测试实例,达到以少数代替全面的效果。
  正交表如何设计呢,这个问题实际很复杂,涉及到组合统计的数学知识,有的正交表甚至到目前为止,还未得出算法。
  我们只能通过已知的模型套上去。
  例如,Dr. Genichi Taguchi 设计的正交表
  https://www.york.ac.uk/depts/maths/tables/orthogonal.htm
  Technical Support ( support.sas.com ) com 提供的
  http://support.sas.com/techsup/technote/ts723_Designs.txt
  首先,我们来看看基本的概念。
  因素:被测的元素称为因素,例如上面的性别,班级,成绩,均为因素,因素的个数我们记为k,此处k=3
  水平:因素的可能值,称为水平。例如班级的可能值为1或2。水平的个数我们记为m,此处正好每个因素的水平都是2,此处m=2。
  那么正交表的行数n的计算公式为,n=k*(m-1)+1,此处为n=3*(2-1)+1=4。即共有4行。
  我们通常用L表示这个正交表,完整的表示为Ln(mk)
  如果每个因素的水平数相等,我们称之为单一水平正交表,例如本例子就是,L4(23)
  各列水平数不完全相同的正交表称为混合水平正交表。如L8(4124),表示有一个因素的水平为4,有4个因素的水平为2。
  按照这个表达式,我们可以去套用已知的正交表。例如本例子是L4(23),从上面提供的两个链接均可以查到例子,虽然表达方式略有不同,但实际是一样的,我们从http://support.sas.com/techsup/technote/ts723_Designs.txt 查到,其正交表的格式为:
  23     n=4
  000
  011
  101
  110
  此处0,1是对可能值的编号,例如,我们可以将(0,1)分别映射为(女,男)(1班,2班)(及格,不及格)
  按照上面的格式,
  000:女  1班  及格
  011:女  2班  不及格
  101:男  1班  不及格
  110:男  2班  及格
  这就是我们所得到的正交表。
   六.总结
  功能测试方法还有很多,例如因果图法,状态转换测试法等,他们都略为复杂,像正交实验法一样,有各自的一套东西,不过本质都是通过画图,让我们更好的思考,最后转化成判定表。
  实际上常用的是前面五种方法,包括:等价类划分法、边界值分析法、错误推测法、判定表法、正交实验法。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325783783&siteId=291194637