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. plsql 通过修改配置文件的方式实现数据库的连接

    查看oracle的安装位置: XP系统: 开始>>所有程序>>>Oracle-OraDb10g_home1>>>配置和移植工具>>>右 ...

  2. Netty:option和childOption参数设置说明

    Channel配置参数 (1).通用参数 CONNECT_TIMEOUT_MILLIS :   Netty参数,连接超时毫秒数,默认值30000毫秒即30秒. MAX_MESSAGES_PER_REA ...

  3. Centos 使用Systemctl报Error getting authority: Error initializing authority: Error calling StartServiceByName for org.freedesktop.PolicyKit1: Timeout was reached (g-io-error-quark, 24)

    在使用centos7.4 安装服务的时候报错: Error getting authority: Error initializing authority: Error calling StartSe ...

  4. 在windows下编写shell脚本

    注意两点: 1.第一行:#!/bin/bash 2.将文档格式转换为unix,因为在windows下编写shell脚本回车符是\n\r,而linux下的回车符是\n,所以在linux下运行脚本的时候, ...

  5. 135、JS和Android交互范例

    很简单的直接上代码 <uses-permission android:name="android.permission.INTERNET" /> assets/web. ...

  6. 【CF434E】Furukawa Nagisa's Tree 点分治

    [CF434E]Furukawa Nagisa's Tree 题意:一棵n个点的树,点有点权.定义$G(a,b)$表示:我们将树上从a走到b经过的点都拿出来,设这些点的点权分别为$z_0,z_1... ...

  7. 解决Office 2016客户端如何同SharePoint Server2016安装在一起

    前言 Microsoft Office 2016 客户端默认使用新式验证. 在某些配置中,新式验证不受安装有 SharePoint Server 2016 的 Office 2016 客户端的支持,例 ...

  8. Xcode - Xcode10上传应用到AppStore

    Xcode 10 如何上传应用到AppStore?Product->Archive 后,原来Xcode 10 之前的版本是直接有两个按钮,一个upload to AppStore,另一个叫Exp ...

  9. oracle 28000错误解决方法

    ORA-28000: the account is locked-的解决办法 ORA-28000: the account is locked 第一步:使用PL/SQL,登录名为system,数据库名 ...

  10. 给table加边框的样式

    <style> .tb { width: 1600px; text-align: center; border-collapse: collapse; } .tb tr td { bord ...