zoukankan      html  css  js  c++  java
  • 【软件测试】(homework2)错误分析

    1)了解错误类型:

    Fault : A static defect in the software.【一个静态的在软件中产生的错误。】
     
    Failure : External, incorrect behavior with respect to the requirements or other description of the expected behavior.【外部的表现,不正确的行为,相对于预期的行为的要求或其他描述。】
     
    Error : An incorrect internal state that is the manifestation of some fault.【不正确的内部状态,是一种错误的表现形式。】
     
     
    2)RIP模型:
    Reachability 可达性
    Infection 感染性
    Propagation 传播性
     
     
    3)Tarantula 公式:
     
     
     
     
     
     
     
     
     
     
    4)程序用例分析:
     
    要求:
    如下给出两个程序,每个程序给出一个测试用例,并且这个用例出现错误的结果。
    分别回答四个问题:
    ① 分辨错误(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      return i; }
    10  }
    11  return -1;
    12 }
    13 // test: x=[2, 3, 5]; y = 2 
    14 // Expected = 0

    回答:

    ① for循环中的判断条件应该是i>=0,不应该是i>0。

    ②  如果x=0,则不会经过for循环,所以不会执行错误的代码位置。

    ③ 只要是x中和y相等大小的元素不是在x中的第一个位置,那么就会运行了代码行且不会报错。

    例如:x=[1,2,3,4,5] y=3,那么就可以经过代码行,且不会有错误出现。

    ④ 当x中元素个数只有一个时,会出现得到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 
    15 // test: x=[0, 1, 0] 
    16 // Expected = 2

    回答:

    ① for (int i = 0; i < x.length; i++) 有错误,应该是 for (int i = x.length-1; i >= 0; i --)

    ② 所有的测试用例都会经过错误的代码行。

    ③ 当x中只有一个元素时,例如x=[1],这时会运行错误的代码行却没有报错。

    ④ 当x的数组中有0时,会出现得到error没有failure的情况。

  • 相关阅读:
    构造方法
    不死神兔
    类与对象
    成员变量和局部变量的区别
    this关键字的理解
    private关键字理解
    如何设置客户端证书
    有关中文的正则表达式
    Web和证书服务:建立电子商务外部网
    认证服务Web 网页循序渐进指南
  • 原文地址:https://www.cnblogs.com/rosel/p/5252466.html
Copyright © 2011-2022 走看看