Software Testing 2 —— Fault、error and failure小练习
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小练习的更多相关文章
- ST HW2 fault & error & failure
Software Testing 3014218128 牛菲菲 Below are two faulty programs. Each includes a test case that result ...
- 结对编程--fault,error,failure
结对编程对象:叶小娟 对方博客地址:http://www.cnblogs.com/yxj63/ 双方贡献比例:1:1 结对照片: 结对题目:输入一定个数的数字,对其排序后输出最大值. 1 pack ...
- 结对编程学习fault、error、failure三种状态
点滴成就 学习时间 新编写代码行数 博客量(篇) 学习知识点 第一周 10小时 0 0 了解软件工程 第二周 10小时 0 1 项目开题 第三周 15小时 0 1 开通博客.开展项目调查 第四周 20 ...
- 结对编程之Fault、Error、Failure
1.结对说明 结对对象:刘世麟 博客地址:http://www.cnblogs.com/liushilin/ 双方贡献:1:1 2.题目要求 构造程序,分别是: •不能触发Faul ...
- 结对编程——关于Fault、Error、Failure程序设计
一.问题描述: 构造程序,分别是: •不能触发Fault •触发Fault,但是不能触发Error •触发Error,但是不能产生Fai ...
- 结对项目——fault,error,failure的程序设计
一.结对编程内容: 1.不能触发Fault. 2.触发Fault,但是不触发Error. 3.触发Error,但不触发Failure. 二.结对编程人员 1.周宗耀.周浩: 2.结对截图: 三.结对项 ...
- 软件测试中的fault,error,failure
问题:给定两段代码,设计fault,error,failure的测试用例. fault:即引起错误的原因,类似病因. error:类似疾病引起的内部结果. failure:类似疾病引起的症状. 代码1 ...
- 【Software Test】Introduction to Software Testing
Introduction to Software Testing 文章目录 Going to Learn --. Evolution of The Software Industry Errors, ...
- FW:Software Testing
Software Testing Testing with a Purpose Software testing is performed to verify that the completed s ...
随机推荐
- JS保留两位小数的几种方法
四舍五入 以下处理结果会四舍五入: var num =2.446242342; num = num.toFixed(2); // 输出结果为 2.45 不四舍五入 以下处理结果不会四舍五入: 第一种, ...
- java使用代理请求https
我本来在我本机写的代码,本机电脑是可以连外网没限制,对于https和http都可以.但是放在linux服务器上后,因为VM限制了不能访问外网,而且有ssl验证所以就一直报错,要么是连不上线上请求,要么 ...
- 框架源码系列三:手写Spring AOP(AOP分析、AOP概念学习、切面实现、织入实现)
一.AOP分析 问题1:AOP是什么? Aspect Oriented Programming 面向切面编程,在不改变类的代码的情况下,对类方法进行功能增强. 问题2:我们需要做什么? 在我们的框架中 ...
- Houdini技术体系 基础管线(一) : Houdini与Houdini Engine的安装
Houdini 下载与安装 在官网 https://www.sidefx.com/download/ 下载最新的Production Build 版本,当前是16.5版本,需要注册帐号 PS:公司内网 ...
- PXE:kickstart配置文件:全自动安装centos、redhat 系统的配置
default menu.c32 #多网卡,其实centos7会自动处理,默认使用第一个网卡 label centos76 menu label ??? centos76 from ftp timeo ...
- iOS 指导文章
1. iOS 后台运行实现总结 http://www.jianshu.com/p/d3e279de2e32 2. C语言的各种版本:C89,AMD1,C99,C11:http://www.tuicoo ...
- springboot 2.0 mariadb hikari-cp连接池
直到今天 2018年9月29日 10:00:38 ,hikari-cp 在maven 官方仓库最新版本为2.6 SpringBoot 2.0.5 控制台输出,默认的是 2.7.9 spring-boo ...
- No Ads for Blogs
最近浏览器出问题了还是博客园登录的问题. 每次进入自己博客都要输入密码. 然后进入某一篇博文查看时,底部总会有些垃圾广告. 怎么办呢. 好吧,真抱歉,为了营造良好的阅读环境,只好给你屏蔽掉了. 其实也 ...
- WKWebView实现网页静态资源优先从本地加载
前言:最近微信的小游戏跳一跳特别的火,顺便也让h5小游戏更加的火热.另外微信小程序,以及支付宝的小程序都是用H5写的.无论是小游戏还是小程序,这些都需要加载更多的资源文件,处理更多的业务.这些都对网页 ...
- php算法题
一群猴子排成一圈,按1,2,…,n依次编号.然后从第1只开始数,数到第m只,把它踢出圈,从它后面再开始数,再数到第m只,在把它踢出去…,如此不停的进行下去,直到最后只剩下一只猴子为止,那只猴子就叫做大 ...