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 ...
随机推荐
- windows下JDK环境配置与Android SDK环境配置
一.JDK环境配置1.配置变量名:JAVA_HOME变量值:jdk安装的绝对路径. 变量名:Path(在系统变量中找到并选中Path点击下面的编辑按钮,不要删除原本变量值中的任何一个字母,在这个变量值 ...
- [转]application.properties详解 --springBoot配置文件
本文转载:http://blog.csdn.net/lpfsuperman/article/details/78287265###; # spring boot application.propert ...
- CentOS7搭建以太坊私有链
1. 环境准备:Win10 64位安装 VM VirtualBox,操作系统版本: CentOS-7-x86_64-Everything-1611.iso(7.71G). 切换root账号,方便安装程 ...
- Ceph相关
Ceph基础知识和基础架构简介 http://www.xuxiaopang.com/2020/10/09/list/#more大话Ceph http://www.xuxiaopang.com/2016 ...
- 解决vscode无法提示golang的问题
https://github.com/Microsoft/vscode-go/wiki/Go-with-VS-Code-FAQ-and-Troubleshooting Q: Auto-completi ...
- 运营商挂时长神器,批量导入账号,导出账号状态,随机修改MAC地址
话不多说,直接上图 可批量导入账号,同时修改广域网口MAC地址 导出账号状态,包括在线时长,MAC,IP地址等等
- minicom for Mac 配置
安装:brew install minicom 配置: 串口是:dev/tty.usbserial minicons -s 配置一下: 流控要关掉,不然输入不了
- 【Python】博客信息爬取-微信消息自动发送
1.环境安装 python -m pip install --upgrade pip pip install bs4 pip install wxpy pip install lxml 2.博客爬取及 ...
- python目录遍历文件名称替换
# -*- coding:utf-8 -*- import os import os.path import shutil import chardet import codecs mysql_fil ...
- TortoiseGit功能介绍
TortoiseGit功能介绍 使用方便 强大的提交对话框 每个项目设置 最小日志消息长度,以避免意外提交空日志消息 用于拼写检查的语言 与问题跟踪系统集成 有用的工具 有多种语言版本 Tortois ...