码迷,mamicode.com
首页 > 其他好文 > 详细

软件测试作业2 — 软件测试中的错误Failure, Error, Fault的区别

时间:2017-03-01 21:12:08      阅读:497      评论:0      收藏:0      [点我收藏+]

标签:第一个   error   spec   correct   nts   cte   系统   equals   ted   

软件测试中的错误Failure, Error, Fault的区别:

Failure: External, incorrect behavior with respect to the requirements or other description of the expected behavior(预期行为出错或与其他的外部行为描述不符)。指软件在运行时出现的功能的丧失,类似于看病时病人发病的症状。

Fault: A static defect in the software(软件中的静态缺陷)。指可能导致系统或功能失效的异常条件,类似于病人发病的病因。

Error: An incorrect internal state that is the manifestation of some fault(不正确的内部状态,是一些故障的表现)指计算、观察或测量值或条件,与真实、规定或理论上正确的值或条件之间的差异。Error是能够导致系统出现Failure的系统内部状态。类比于医生寻找的导致症状的内部情况,如血压,血糖等。

 

题目1:

 1 public int findLast (int[] x, int y) {
 2 //Effects: If x==null throw NullPointerException
 3 // else return the index of the last element
 4 // in x that equals y.
 5 // If no such element exists, return -1
 6 for (int i=x.length-1; i > 0; i--)
 7 {
 8 if (x[i] == y)
 9 {
10 return i;
11 }
12 }
13 return -1;
14 }
15 // test: x=[2, 3, 5]; y = 2
16 // Expected = 0

1.  找到程序中的Fault:

  Fault:循环条件出错,i>0会忽略数组中的第一个值,故应改为i>=0.

2.  设计一个未执行Fault的测试用例:

  x=null; y=5

3.  设计一个执行Fault,没有触发Error的测试用例:

  数组x的第一个元素不是与y相等的唯一的元素即可避免Error,如x = [2, 3, 2, 6],  y = 2.

4.  设计一个触发Error,但不导致Failure的测试用例:

  当数组只有一个元素的时候,循环无法进行,返回-1,触发Error。但若x中唯一的元素与y不相等,则Failure不会产生。如x = [7], y = 4。

 

 题目2:

 1 public static int lastZero (int[] x) {
 2 //Effects: if x==null throw NullPointerException
 3 // else return the index of the LAST 0 in x.
 4 // Return -1 if 0 does not occur in x
 5 for (int i = 0; i < x.length; i++)
 6 {
 7 if (x[i] == 0)
 8 {
 9 return i;
10 }
11 } return -1;
12 }
13 // test: x=[0, 1, 0]
14 // Expected = 2

1.  找到程序中的Fault:

  Fault:循环错误,程序为从前往后遍历,应改为从后往前遍历即 for (int i=x.length-1; i >= 0; i--)。

2.  设计一个未执行Fault的测试用例:

  程序总会执行int i=0 故肯定会执行Fault,及时x=null也会执行Fault。

3.  设计一个执行Fault,没有触发Error的测试用例:

  当x=null时执行Fault且会抛出异常但不会触发Error。

4.  设计一个触发Error,但不导致Failure的测试用例:

  当数组中不为空且只有一个元素等于0时或者没有元素为0时会触发Error但不会导致Failure。如x=[1, 0, 2].

软件测试作业2 — 软件测试中的错误Failure, Error, Fault的区别

标签:第一个   error   spec   correct   nts   cte   系统   equals   ted   

原文地址:http://www.cnblogs.com/JasonLiuys/p/6485997.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!