• 软件测试作业二——找出程序中的错误


    一、软件程序中的错误

         软件程序中的错误有三种:faults(故障), errors(错误), failures(失败)。

         软件故障(faults):软件中的静态缺陷。

         软件错误(errors):不正确的内部状态,该状态是某个故障的表现。

         软件失败(failures):与需求或其他期望行为的描述有关的,外部的,不正确的行为。

    二、分析下列程序

       程序一:

       

    public int findLast (int[] x,int y){
       //Effects:If x==null throw NullPointerException
      //else return the index of the last element in x that equals y.
     //if no such element exists,return -1.
        for (int i= x.length-1;i>0;i--)
        {
    if(x[i]==y) { return i; } } return -1; }

     (1) 程序故障: for 循环应该为  i>=0.

    (2) 不会执行故障的测试用例:x 为空时,不会执行故障。

    (3) 执行故障不会导致错误状态的测试用例:x=[5,6,7] y=6时,执行了故障,但没有出现错误的状态。

    (4)导致错误而不是失败的测试用例:x=[2,3,4],y=7时。

    public static intlastZero(int[] x) {
    //Effects: if x==null throw Null PointerException// else return the index of the LAST 0 in x.
    // Return -1 if 0 does not occur in x
    for (inti= 0; i< x.length; i++)
    {
    if (x[i] == 0)
    {
    return i;
    }
    } return -1;
    }

     (1) 程序故障: for 循环应该为  for (int i = x.length; i >=0; i--)

    (2) 不会执行故障的测试用例:所有输入都会执行故障。

    (3) 执行故障不会导致错误状态的测试用例:x=[4],x 只有一个元素时,执行了故障,但没有出现错误的状态。

    (4)导致错误而不是失败的测试用例:x=[2,0,4]。

  • 相关阅读:
    OpenGL完整实例
    OpenGL
    Socket(2)
    Socket(1)
    Stream,Reader/Writer,Buffered的区别(2)
    Stream,Reader/Writer,Buffered的区别(1)
    SQLite数据库与Contentprovider(2)
    SQLite数据库与Contentprovider(1)
    数据存储和访问
    AIDL与service
  • 原文地址:https://www.cnblogs.com/xiao94/p/5252216.html
Copyright © 2020-2023  润新知