Questions:

Below are two faulty programs. Each includes a test case that results in failure. Answer the following questions (in the next slide) about each program.

1、Identify the fault.


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

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

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

Program One:

 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-; i > ; i--)
{
if (x[i] == y) {
return i;
}
}
return -;
}
// test: x=[2, 3, 5]; y = 2
// Expected = 0

Answers:

1、错误代码:

for(int i = x.length-; i > ; i--)

原因:应共遍历x.length次,且数组下标从零开始。

改正为:

for(int i = x.length-; i >= ; i--)

2、A test case: x = [] ——> If x == null throw NullPointerException,不会执行fault。

3、A test case: x = [2, 3, 5]; y = 3 ——> The result is 1,执行了fault,且结果正确。

4、A test case: x = [2, 3, 5]; y = 4 ——> The result is -1,是error,不是failure。


Program Two:

 public static int lastZero (int[] x) {
// Effects: if x==null throw NullPointerException
// else return the index of the LAST 0 in x.
// Return -1 if 0 does not occur in x
for (int i = ; i < x.length; i++)
{
if (x[i] == ) {
return i;
}
}
return -;
}
// test: x=[0, 1, 0]
// Expected = 2

Answers:

1、错误代码:

for (int i = ; i < x.length; i++)

原因:返回的应该是最后一个零的位置,上述代码返回的是第一个零的位置,且数组下标从零开始。

改正为:

for (int i = x.length-; i >= ; i--)

2、A test case: x = [] ——> If x == null throw NullPointerException,不会执行fault。

3、A test case: x = [1, 0, 1] ——> The result is 1,执行了fault,且结果正确。

4、A test case: x = [2, 3, 5] ——> The result is -1,是error,不是failure。

Software Testing 2 —— Fault、error and failure小练习的更多相关文章

  1. ST HW2 fault & error & failure

    Software Testing 3014218128 牛菲菲 Below are two faulty programs. Each includes a test case that result ...

  2. 结对编程--fault,error,failure

    结对编程对象:叶小娟 对方博客地址:http://www.cnblogs.com/yxj63/ 双方贡献比例:1:1 结对照片: 结对题目:输入一定个数的数字,对其排序后输出最大值.   1 pack ...

  3. 结对编程学习fault、error、failure三种状态

    点滴成就 学习时间 新编写代码行数 博客量(篇) 学习知识点 第一周 10小时 0 0 了解软件工程 第二周 10小时 0 1 项目开题 第三周 15小时 0 1 开通博客.开展项目调查 第四周 20 ...

  4. 结对编程之Fault、Error、Failure

    1.结对说明 结对对象:刘世麟  博客地址:http://www.cnblogs.com/liushilin/ 双方贡献:1:1 2.题目要求  构造程序,分别是:         •不能触发Faul ...

  5. 结对编程——关于Fault、Error、Failure程序设计

    一.问题描述:         构造程序,分别是:         •不能触发Fault         •触发Fault,但是不能触发Error         •触发Error,但是不能产生Fai ...

  6. 结对项目——fault,error,failure的程序设计

    一.结对编程内容: 1.不能触发Fault. 2.触发Fault,但是不触发Error. 3.触发Error,但不触发Failure. 二.结对编程人员 1.周宗耀.周浩: 2.结对截图: 三.结对项 ...

  7. 软件测试中的fault,error,failure

    问题:给定两段代码,设计fault,error,failure的测试用例. fault:即引起错误的原因,类似病因. error:类似疾病引起的内部结果. failure:类似疾病引起的症状. 代码1 ...

  8. 【Software Test】Introduction to Software Testing

    Introduction to Software Testing 文章目录 Going to Learn --. Evolution of The Software Industry Errors, ...

  9. FW:Software Testing

    Software Testing Testing with a Purpose Software testing is performed to verify that the completed s ...

随机推荐

  1. js命名空间的函数namespace

    这是一个扩展函数,需要初期加载的时候加载到适当的位置. 具体函数体如下: $.namespace = function() { var a=arguments, o=null, i, j, d; fo ...

  2. Android 8 蓝牙打开过程

    packages\apps\Settings\src\com\android\settings\bluetooth\BluetoothEnabler.java @Override public boo ...

  3. ubuntu下同时安装anaconda2与anaconda3,并分别安装与之对应的软件

    1.安装anaconda2 参考网址:https://www.cnblogs.com/chamie/p/8876271.html 2.安装anaconda3 转载:https://blog.csdn. ...

  4. 【目录】Docker 基本操作

    1 容器基本操作 : https://www.cnblogs.com/defineconst/p/9990611.html 2 容器启动退出 : https://www.cnblogs.com/def ...

  5. 自己动手实现RPC

    一.需求:用户管理系统(UMS),仓库管理系统(WMS),订单管理系统(OMS) 现在OMS有一张订单表:[订单id,用户id,商品id,订单状态,订单时间],需要在客户端展示此订单对应的用户详情和商 ...

  6. spark连数据库

    DataFrame提供了一条联结所有主流数据源并自动转化为可并行处理格式的渠道,通过它Spark能取悦大数据生态链上的所有玩家,无论是善用R的数据科学家,惯用SQL的商业分析师,还是在意效率和实时性的 ...

  7. [原]Jenkins(一)---我理解的jenkins是这样的(附全套PDF下载)

    /** * lihaibo * 文章内容都是根据自己工作情况实践得出. *版权声明:本博客欢迎转发,但请保留原作者信息! http://www.cnblogs.com/horizonli/p/5330 ...

  8. Linux下的awk文本分析命令实例(一)

    1.  入门实例1.1 显示最近登录的5个帐号: [root@localhost ~]# | awk '{print $1}' root root root root reboot 1.2 如果只是显 ...

  9. springboot中Properties注解的实现

    关于@PropertySources注解的理解:http://www.imooc.com/article/252889?block_id=tuijian_wz public interface Pro ...

  10. CPanel/服务器文件及目录

    cPanel服务器默认的各主要目录及配置文件的路径.cPanel服务器很多配置文件的路径和通常情况下安装LAMP的不同,另外还有很多是属于cPanel面板自己的配置文件. 目录 1 Apache 2  ...