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的更多相关文章

  1. 101+ Manual and Automation Software Testing Interview Questions and Answers

    101+ Manual and Automation Software Testing Interview Questions and Answers http://www.softwaretesti ...

  2. Exploratory Software Testing

    最近找到去年上半年看过一本关于测试方面书籍的总结笔记,一直放在我的个人U盘里,当时是用Xmind记录的,现在重新整理下分享给大家了! James A.Whittaker [美] 詹姆斯·惠特克(软件测 ...

  3. 软件测试software testing summarize

    软件测试(英语:software testing),描述一种用来促进鉴定软件的正确性.完整性.安全性和质量的过程.软件测试的经典定义是:在规定的条件下对程序进行操作,以发现程序错误,衡量软件质量,并对 ...

  4. 读书笔记-Software Testing(By Ron Patton)

    Software Testing Part I:The Big Picture 1.Software Testing Background Bug's formal definition 1.The ...

  5. software testing

    Software Testing Software testing is the process of evaluation a software item to detect differences ...

  6. Software Testing Techniques LAB 02: Selenium

    1. Installing 1. Install firefox 38.5.1 2. Install SeleniumIDE    After installing, I set the view o ...

  7. 探索式软件测试—Exploratory Software Testing

    最近找到去年上半年看过一本关于测试方面书籍的总结笔记,一直放在我的个人U盘里,当时是用Xmind记录的,现在重新整理下分享给大家了! James A.Whittaker [美] 詹姆斯·惠特克(软件测 ...

  8. FW:Software Testing

    Software Testing Testing with a Purpose Software testing is performed to verify that the completed s ...

  9. 《The art of software testing》的一个例子

    这几天一直在看一本书,<The art of software testing>,里面有一个例子挺有感触地,写出来和大家分享一下: [问题] 从输入对话框中读取三个整数值,这三个整数值代表 ...

  10. Software Testing Concepts

    Software Testing Concepts

随机推荐

  1. mysql事务隔离级别及传播机制

    TRANSACTION(事务隔离级别) 在说明事务隔离级别之前先说一下脏读.不可重复读.幻读这三个概念. 脏读:一个事务读取到另一事务未提交的更新新据.当一个事务正在访问数据,并且对数据进行了修改,而 ...

  2. [ java 工具类] xml字符串解析成Map(DOM解析)

    package com.tencent.jungle.wechat.util; import com.google.inject.Singleton; import org.w3c.dom.Docum ...

  3. ubuntu下同时安装anaconda2与anaconda3,并分别安装与之对应的软件

    1.安装anaconda2 参考网址:https://www.cnblogs.com/chamie/p/8876271.html 2.安装anaconda3 转载:https://blog.csdn. ...

  4. spring 测试类test测试方法

    实例掩码地址为:孔浩组织结构设计 web.xml配置文件: <!-- Spring 的监听器可以通过这个上下文参数来获取beans.xml的位置 --> <context-param ...

  5. 我们正在招聘java工程师,想来美团工作吗?

    我们希望你有? 1.3年以上Java服务器开发经验,精通Java及面向对象设计开发,熟悉主流web框架 2.熟悉网络编程,熟悉TCP/IP协议,熟悉互联网应用协议 3.有大规模分布式系统设计与开发经验 ...

  6. 如何在Linux下修改Mysql的用户(root)密码

    下面给大家分享下在Linux下如何修改Mysql的用户(root)的密码,分两种情况:第一种当拥有原来的mysql的root密码,第二种情况忘记原来的mysql的root的密码. 修改的用户都以roo ...

  7. monit配置文件

    监控模式:(MONITRING MODE) Monit支持三种监控模式, active--Monitj监控一个服务,为了防止一系列问题,Monit会执行以及发送警报,停止,启动,重启,这是一个缺省的模 ...

  8. ux.form.field.Month 只能选年、月的时间扩展

    效果如图,亲测6.2.1版本可用,用法同时间选择控件 //月弹窗扩展 //只选月 Ext.define('ux.picker.Month', { extend: 'Ext.picker.Month', ...

  9. Spring AOP @AspectJ 入门基础

    需要的类包: 1.一个简单的例子 Waiter接口: package com.yyq.annotation; public interface Waiter { void greetTo(String ...

  10. 用dx生成dex时遇到class name does not match path

    前言 用dx生成dex时遇到class name (Hello) does not match path这个问题还弄了挺久,这里就简单的记录一下. 步骤 首先是dx工具是在Android的SDK里面的 ...