Software Testing 软件测试 HW2 Fault Error Failure

本文分析了两个程序中存在的缺陷,并为每个程序提供了不执行缺陷、执行缺陷但不导致错误状态、导致错误但非失败的测试案例。

There are two programs.

For program 1

 1 public int findLast(int[] x, int y){
 2   //Effects: If x==null throw NullPointerException
 3   //else return the index of the last elements
 4   //in x that equals y.
 5   //If no such elements 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 }    

1、Identify Identify the fault. 

    i > 0, it should be i ≥ 0, the searching should be stopped at 0, not 1.

2、If possible, identify a test case that does not execute the fault. (Reachability) .

    x=null,  y=2

    It will not execute the statement i>0 where the fault locates. 

3、If possible, identify a test case that executes the fault, does not result in an error state.

    x=[0, 1, 2],  y=1

    It will execute the statement i>0 and have the same state if i>0 is fixed by i≥0, not result in an error state.

4、If possible, identify a test case that results in an error, but not a failure.

      x=[0, 1, 2],  y=3

    It will have an error state if the fault is fixed, but will have the same results, both -1.

For program 2

 1 public static int lastZero(int [] x){
 2   //Effects: ifx==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 }

1、Identify Identify the fault. 

    for(i=0; i<length; i++) should be for(i=length-1; i≥0; i--), it should search from end to start to get the index of the LAST 0.

2、If possible, identify a test case that does not execute the fault. (Reachability) .

    x=null

    It will not execute the statement where the fault locates. 

3、If possible, identify a test case that executes the fault, does not result in an error state.

    x=[0]

    It will execute the statement where the fault locates and have the same state, if the fault is fixed.

4、If possible, identify a test case that results in an error, but not a failure.

           x=[1, 2, 3]

    It will have an error state if the fault is fixed, but will have the same results, both -1.

转载于:https://www.cnblogs.com/wazxser/p/6481741.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值