Software Testing 3
Questions:
• 7. Use the following method printPrimes() for questions a–d.
基于Junit及Eclemma(jacoco)实现一个主路径覆盖的测试。
/*****************************************************************
* Finds and prints n prime integers
* Jeff Offutt, Spring 2003
*****************************************************************/
private static void printPrimes(int n)
{
int curPrime; // Value currently considered for primeness
int numPrimes; // Number of primes found so far;
boolean isPrime; // Is curPrime prime?
int[] primes = new int[MAXPRIMES]; // The list of prime numbers. // Initialize 2 into the list of primes.
primes[0] = 2;
numPrimes = 1;
curPrime = 2;
while(numPrimes < n)
{
curPrime++; // next number to consider...
isPrime = true;
for(int i = 0; i <= numPrimes-1; i++)
{ // for each previous prime.
if(isDivisible(primes[i], curPrime))
{ // Found a divisor, curPrime is not prime.
isPrime = false;
break; // out of loop through primes.
}
}
if(isPrime)
{ // save it!
primes[numPrimes] = curPrime;
numPrimes++;
}
} // End while // print all the primes out.
for(int i = 0; i <= numPrimes-1; i++)
{
System.out.println("Prime: " + primes[i]);
}
}// End printPrimes.
(a) Draw the control flow graph for the printPrimes() method.
(b) Consider test cases t1 = (n = 3) and t2 = (n = 5). Although these tour the same prime paths in printPrimes(), they do not necessarily find the same faults. Design a simple fault that t2 would be more likely to discover than t1 would.
(c) For printPrimes(), find a test case such that the corresponding test path visits the edge that connects the beginning of the while statement to the for statement without going through the body of the while loop.
(d) Enumerate the test requirements for node coverage, edge coverage, and prime path coverage for the path for printPrimes().
Answers:
(a)
(b) MAXPRIMES >= n
所以当MAXPRIMES = 4时,t2会发生数组越界,而t1不会。
(c) n = 1;
(d)点覆盖:TR = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
边覆盖:TR = {(1,2), (2,3), (2,11), (3,4), (4,5), (4,8), (5,6), (5,7), (6,8), (7,4), (8,9), (8,10), (9,10), (10,2), (11,12), (12,13), (12,15), (13,14), (14,12)}
主路径覆盖:
TR = {(1, 2, 3, 4, 5, 6, 8, 9, 10),(1, 2, 3, 4, 5, 6, 8, 10),(1, 2, 3, 4, 8, 9, 10),(1, 2, 3, 4, 8, 10),(1, 2, 3, 4, 5, 7),(1, 2, 11, 12, 13, 14),(1, 2, 11, 12, 15),
(2, 3, 4, 5, 6, 8, 9, 10, 2),(2, 3, 4, 5, 6, 8, 10, 2),(2, 3, 4, 8, 9, 10, 2),(2, 3, 4, 8, 10, 2),
(3, 4, 5, 6, 8, 9, 10, 2, 11, 12, 13, 14),(3, 4, 5, 6, 8, 9, 10, 2, 11, 12, 15),(3, 4, 5, 6, 8, 10, 2, 11, 12, 13, 14),(3, 4, 5, 6, 8, 10, 2, 11, 12, 15),(3, 4, 8, 9, 10, 2, 11, 12, 13, 14),(3, 4, 8, 9, 10, 2, 11, 12, 15),(3, 4, 8, 10, 2, 11, 12, 13, 14),(3, 4, 8, 10, 2, 11, 12, 15),
(4, 5, 7, 4),(4, 5, 6, 8, 9, 10, 2, 3, 4),(4, 5, 6, 8, 10, 2, 3, 4),
(5, 7, 4, 5),(5, 6, 8, 9, 10, 2, 3, 4, 5),(5, 6, 8, 10, 2, 3, 4, 5),(5, 7, 4, 8, 9, 10, 2, 3),(5, 7, 4, 8, 10, 2, 3),(5, 7, 4, 8, 9, 10, 2, 11, 12, 13, 14),(5, 7, 4, 8, 10, 2, 11, 12, 13, 14),(5, 7, 4, 8, 9, 10, 2, 11, 12, 15),(5, 7, 4, 8, 10, 2, 11, 12, 15),
(6, 8, 9, 10, 2, 3, 4, 5, 6),(6, 8, 10, 2, 3, 4, 5, 6),(6, 8, 9, 10, 2, 3, 4, 5, 7),(6, 8, 10, 2, 3, 4, 5, 7),
(7, 4, 5, 7),(7, 4, 5, 6, 8, 9, 10, 2, 3, 4),(7, 4, 5, 6, 8, 10, 2, 3, 4),(7, 4, 5, 6, 8, 9, 10, 2, 11, 12, 13, 14),(7, 4, 5, 6, 8, 10, 2, 11, 12, 13, 14),(7, 4, 5, 6, 8, 9, 10, 2, 11, 12, 15),(7, 4, 5, 6, 8, 10, 2, 11, 12, 15),
(8, 10, 2, 3, 4, 8),(8, 9, 10, 2, 3, 4, 8),(8, 10, 2, 3, 4, 5, 6, 8),(8, 9, 10, 2, 3, 4, 5, 6, 8),
(9, 10, 2, 3, 4, 5, 6, 8, 9),(9, 10, 2, 3, 4, 8, 9),
(10, 2, 3, 4, 5, 6, 8, 10),(10, 2, 3, 4, 5, 6, 8, 9, 10),(10, 2, 3, 4, 8, 10),(10, 2, 3, 4, 8, 9, 10),
(12, 13, 14, 12),
(13, 14, 12, 15),(13, 14, 12, 13),
(14, 12, 13, 14)}
(附加)基于Junit及Eclemma(jacoco)实现一个主路径覆盖的测试:
首先,假设MAXPRIMES=10并补全代码;
其次,确定测试用例并编写测试文件;
Software Testing 3的更多相关文章
- 101+ Manual and Automation Software Testing Interview Questions and Answers
101+ Manual and Automation Software Testing Interview Questions and Answers http://www.softwaretesti ...
- Exploratory Software Testing
最近找到去年上半年看过一本关于测试方面书籍的总结笔记,一直放在我的个人U盘里,当时是用Xmind记录的,现在重新整理下分享给大家了! James A.Whittaker [美] 詹姆斯·惠特克(软件测 ...
- 软件测试software testing summarize
软件测试(英语:software testing),描述一种用来促进鉴定软件的正确性.完整性.安全性和质量的过程.软件测试的经典定义是:在规定的条件下对程序进行操作,以发现程序错误,衡量软件质量,并对 ...
- 读书笔记-Software Testing(By Ron Patton)
Software Testing Part I:The Big Picture 1.Software Testing Background Bug's formal definition 1.The ...
- software testing
Software Testing Software testing is the process of evaluation a software item to detect differences ...
- Software Testing Techniques LAB 02: Selenium
1. Installing 1. Install firefox 38.5.1 2. Install SeleniumIDE After installing, I set the view o ...
- 探索式软件测试—Exploratory Software Testing
最近找到去年上半年看过一本关于测试方面书籍的总结笔记,一直放在我的个人U盘里,当时是用Xmind记录的,现在重新整理下分享给大家了! James A.Whittaker [美] 詹姆斯·惠特克(软件测 ...
- FW:Software Testing
Software Testing Testing with a Purpose Software testing is performed to verify that the completed s ...
- 《The art of software testing》的一个例子
这几天一直在看一本书,<The art of software testing>,里面有一个例子挺有感触地,写出来和大家分享一下: [问题] 从输入对话框中读取三个整数值,这三个整数值代表 ...
- Software Testing Concepts
Software Testing Concepts
随机推荐
- ubuntu 使用旧式Gnome风格的菜单
sudo apt-add-repository ppa:diesch/testing sudo apt-get update sudo apt-get install classicmenu-indi ...
- Android中的AlarmManager的使用
AlarmManager是Android中的一种系统级别的提醒服务,它会为我们在特定的时刻广播一个指定的Intent.而使用Intent的时候,我们还需要它执行一个动作,如startActivity, ...
- name转json
^(\{)?(?<=\n)(.*)(\})?$ "$2":"", UserId UserOrderId ChargeAccount BuyNum Good ...
- JS数组常用方法总结
JavaScript中创建数组有两种方式 (一)使用 Array 构造函数: var arr1 = new Array(); //创建一个空数组 var arr2 = new Array(20); / ...
- How to write threats to validity?
Paper reference Threats to construct validity are concerned with the relationship between theory and ...
- 排序算法--插入排序(Insertion Sort)_C#程序实现
排序算法--插入排序(Insertion Sort)_C#程序实现 排序(Sort)是计算机程序设计中的一种重要操作,也是日常生活中经常遇到的问题.例如,字典中的单词是以字母的顺序排列,否则,使用起来 ...
- JAVA用QRCode生成二维码
QRCode jar下载地址: 生成:http://www.swetake.com/qrcode/index-e.html 读取:https://zh.osdn.net/projects/qrcode ...
- vue.js学习资料
vue.js学习VuejsAPI教程 https://vuejs.org.cn/guide/Vuejs自己的构建工具 http://www.jianshu.com/p/f8e21d87a572如何用v ...
- Java课程寒假之开发记账本软件(网页版)之三
一.实现基础功能之一(查询)(补) 在上一篇中解释的不够详细,在本篇中补充一下指定日期查询,其实和查询没有什么区别,就是设置select下拉框来对于日期的起始与结束日期,然后就是一个简单的mysql语 ...
- JBPM工作流(五)——执行流程实例
概念: ProcessInstance,流程实例:代表流程定义的一次执行.如:张三昨天按请假流程请了一次假.一个流程实例包括了所有运行阶段,其中最典型的属性就是跟踪当前节点的指针,如下图. Execu ...