zoukankan      html  css  js  c++  java
  • 软件测试作业二——找出程序中的错误

    一、软件程序中的错误

         软件程序中的错误有三种: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]。

  • 相关阅读:
    2015.05.12:json的常用处理方式
    好菜都得花功夫做
    网站从 IIS6 迁移至 IIS7 后的通配符脚本映射权限配置不当可能导致403错误
    ELearning是学习系统而不是教育系统
    空难与软件开发(一)
    “模态”对话框和“后退”按钮
    闭包解析(Fun with closure)
    关于CultureInfo的两个问题
    从来就不可能精通:关于Boxing
    Windows RT 应用程序开发介绍培训的讲义
  • 原文地址:https://www.cnblogs.com/xiao94/p/5252216.html
Copyright © 2011-2022 走看看