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 ...
随机推荐
- 服务器返回:type":"Buffer","data":
接口中返回"type":"Buffer","data":[32,232,175,183,233,151,174,229,177,177,23 ...
- COUNT分组条件去重的sql统计语句示例(mysql)
常规情况下的sql分组统计为: ) from 表 where 条件 group by 字段; 但是有时往往需要添加不同的条件已经去重的统计以上语句就不能满足需求. 解决方案为: 1.添加条件的统计方案 ...
- swiper4自动轮播切换手动触碰后停止踩坑——属性disableOnInteraction
swiper4轮播设置autoplay自动切换后,即默认设置: <script> var mySwiper = new Swiper('.swiper-container', { auto ...
- Ubuntu 10.04下架设流媒体服务器
Ubuntu 10.04下架设流媒体服务器 个人建议:使用DarwinStreamingSrvr5.5.5,因为DarwinStreamingSrvr6.0.3安装过程中有很多问题需要解决! 目前主流 ...
- Mysql推荐使用规范(转)
一:基础规范 1.使用InnoDB存储引擎 支持事务.行级锁.并发性能更好.CPU及内存缓存页优化使得资源利用率更高 2.推荐使用utf8mb4字符集 无需转码,无乱码风险, 支持emoji表情以及部 ...
- JDK 5.0 注解知识快速进阶
1.了解注解 对于Java开发人员来说,在编写代码时,除了源程序外,还会使用Javadoc标签对类.方法或成员变量进行注释,一遍使用Javadoc工具生成和源代码配套的Javadoc文件,如@para ...
- J - Printer Queue 优先队列与队列
来源poj3125 The only printer in the computer science students' union is experiencing an extremely heav ...
- 使用stylus
1. 首先确保 node + npm 环境一切正常. 2. 全局安装 stylus: 在命令行中: npm i stylus@latest -g 3. 此时可以创建 .s ...
- weapp-mobx
// weapp-mobx.js const l = console.log; import { autorun } from "./mobx.umd.min"; function ...
- eclipse哪个版本好
Eclipse IDE for Java EE Developers (企业级开发软件,干啥都足够了,300MB左右)