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
随机推荐
- ViZDoom深度预测(Depth Prediction)
代码:github.com/huangshiyu13/ViZDoomDepth 图片被分成3x6的区域,利用模型预测每个区域的平均深度,效果如下图:
- SpirngBoot之整合Swagger2
前言 swagger,中文"拽"的意思.它是一个功能强大的api框架,它的集成非常简单,不仅提供了在线文档的查阅, 而且还提供了在线文档的测试.另外swagger很容易构建rest ...
- 根据xlsx模板生成excel数据文件发送邮件代码
package mail; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundExcept ...
- React Native Android原生模块开发实战|教程|心得|怎样创建React Native Android原生模块
尊重版权,未经授权不得转载 本文出自:贾鹏辉的技术博客(http://blog.csdn.net/fengyuzhengfan/article/details/54691503) 告诉大家一个好消息. ...
- 常见机试题分析Java版
1. 操作系统任务分为系统任务和用户任务两种.其中,系统任务的优先级<50,用户任务的优先级>=50且<=255.优先级大于255的为非法任务,应予以剔除.现有一任务队列task[] ...
- sql知识点记录
order by就是排序. group by就是分组. WHERE语句在GROUP BY语句之前:SQL会在分组之前计算WHERE语句. HAVING语句在GROUP BY语句之后:SQL会在分 ...
- Windows下Codeblocks调试Cocos2d-x项目体验(一次失败的体验)
很久之前的一篇文章有介绍过在Ubuntu下安装Cocos2d-x3.11并使用Codeblock调试Cocos2d-x程序:http://www.cnblogs.com/moonlightpoet/p ...
- MSVCP110.DLL没有被指定在WINDOWS上运行
要重新安装C++ 运行库 为msvcp110.dll是VC++2012的文件 数字代表版本msvcp120是VC++2013的 110是2012的 100是2010的 90是2008的 71是2005 ...
- ux.form.field.Month 只能选年、月的时间扩展
效果如图,亲测6.2.1版本可用,用法同时间选择控件 //月弹窗扩展 //只选月 Ext.define('ux.picker.Month', { extend: 'Ext.picker.Month', ...
- Java 一致性Hash算法的学习
目前我们很多时候都是在做分布式系统,但是我们需把客户端的请求均匀的分布到N个服务器中,一般我们可以考虑通过Object的HashCodeHash%N,通过取余,将客户端的请求分布到不同的的服务端.但是 ...