软件测试(二)之 Failure, Error & Fault

知识回顾数组

  软件测试中的错误主要分为三种:Failure, Error 和 Fault
测试

  下面就分析一下它们的不一样:
ui

  Fault的定义:可能致使系统或功能失效的异常条件(Abnormal condition that can cause an element or an item to fail.),可译为“故障”
  
  Error的定义:计算、观察或测量值或条件,与真实、规定或理论上正确的值或条件之间的差别(Discrepancy between a computed, observed or measured value or condition and the true, specified, or theoretically           correct value or condition.),可译为“错误”。Error是可以致使系统出现Failure的系统内部状态
 

  Failure的定义:当一个系统不能执行所要求的功能时,即为Failure,可译为“失效”。(Termination of the ability of an element or an item to perform a function as required.)spa

  
  三者关系分析
  • 因为人类试图经过上述3个基本术语来覆盖全部现实中的失效场景,因此就有Fault -> Error -> Failure”。即,故障发生了,会致使错误,错误有可能形成系统功能的减弱或丧失
  • 当Fault是另一个组件/系统的失效时,则有Failure (Fault) -> Error -> Failure;当将Fault说成是某组件状态Error时,则有Error (Fault) -> Error -> Failure
  • 事实上,这是一种递归循环的关系,递归关系要成立必须有一个明确的结束条件,这个条件就是要找出Root Cause,不然将没法完成一个失效分析。    

 

  举例指针

  病人告诉医生本身的各类症状,身体没有健康地工做 – Failures code

  医生想找出疾病的根源,如病毒 – Fault
orm

  病人身体状态异常,好比血压较高,心跳不规律等 – Errors

blog

 

实例(HOMEWORK2)递归

   程序1:ci

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

 

  Solution:

  1.Fault: 循环条件没设置好,i > 0会致使循环没法进行到数组第一项,应该改为 i >= 0。

   2.数组x为空时,会抛出空指针错误,循环没法执行,也不会执行上面叙述的Fault。

   3.只要知足数组x[0]不是与y相等的惟一的元素便可避免Error,好比测试用例 x = [1, 2, 3, 4, 5, 6],  y = 2, 这样获得返回结果 Expected = 1, 结果是正确的。

     4.当数组只有一个元素的时候,因为循环没法访问第一个元素(x[0]),因此循环没法进行,永远返回-1,致使Error。此时Failure产生未知, 若是这惟一的元素与y不相等,则Failure也不会产生。测试用例 x = [1], y = 2,此时   返回-1,只有Error,无Failure。

 

  程序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  } 12     return -1; 13 } 14 // test: x=[0, 1, 0] 15 // Expected = 2

 

  Solution:

  1.Fault: 循环错误,从前日后遍历,遇到第一个0便返回其下标,循环应改成for (int i=x.length-1; i >= 0; i--)

   2.因为该程序从前日后遍历,循环至少执行一次,因此总会执行该Fault。

   3.循环若是没法执行便不会致使Error,即数组为空。另外若数组只有一个元素,这样不论如何遍历结果也相同,也不会引起Error。

     4.当数组有一个以上元素且只有一个元素为0时,此时循环返回的是第一个等于0的元素的下标,致使Error。可是因为只有一个元素等于0, 因此同时这也是最后一个等于0的元素的下标,则Failure不会产生。测试用例 x =

       [1,0,1],Expected=1,此时只有Error,无Failure。

相关文章
相关标签/搜索