软件测试作业3:图覆盖的理解及应用

程序代码如下:

 1 /*******************************************************
 2      * Finds and prints n prime integers
 3      * Jeff Offutt, Spring 2003
 4      ******************************************************/
 5     public static void printPrimes (int n)
 6     {
 7         int curPrime; // Value currently considered for primeness
 8         int numPrimes; // Number of primes found so far.
 9         boolean isPrime; // Is curPrime prime?
10         int [] primes = new int [MAXPRIMES]; // The list of prime numbers.
11
12         // Initialize 2 into the list of primes.
13         primes [0] = 2;
14         numPrimes = 1;
15         curPrime = 2;
16         while (numPrimes < n)
17         {
18             curPrime++; // next number to consider ...
19             isPrime = true;
20             for (int i = 0; i <= numPrimes-1; i++)
21             { // for each previous prime.
22                 if (curPrime%primes[i]==0)
23                 { // Found a divisor, curPrime is not prime.
24                     isPrime = false;
25                     break; // out of loop through primes.
26                 }
27             }
28             if (isPrime)
29             { // save it!
30                 primes[numPrimes] = curPrime;
31                 numPrimes++;
32             }
33         } // End while
34
35         // Print all the primes out.
36         for (int i = 0; i <= numPrimes-1; i++)
37         {
38             System.out.println ("Prime: " + primes[i]);
39         }
40     } // end printPrimes

题目要求如下:

  (a)Draw the control flow graph

(b)t1=(n=3),t2=(n=5) Design a simple fault that t2 would be more likely to discover than t1 would.

(c)Find a test case that connects the beginning of the while statement to for statement without going through the body of while loop.

(d)Enumerate the test requirements for node coverage, edge coverage, and prime path coverage.

– 基于Junit及Eclemma( jacoco)实现一个主路径覆盖的测试。

Solutions:

a)控制流图

b)t1=(n=3),t2=(n=5).当数组越界时,t2更能发现问题。

c)当n=1时,程序跳过循环。

d)node coverage:{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}

edge coverage:{(1,2),(2,3),(3,4),(4,5),(5,6),(5,7),(6,7),(6,8),(7,4),(8,9),(9,10),(10,11),(9,11),(4,8),(2,12),(11,2),(12,13),(13,14),(14,15),(15,13),(13,16)}

prime path coverage:

{(1,2,3,4,5,6,7),

(1,2,3,4,5,7),

(1,2,3,4,5,6,8,9,10,11),

(1,2,3,4,8,9,10,11),

(1,2,3,4,5,6,8,9,11),

(1,2,3,4,8,9,11),

(1,2,12,13,14,15),

(1,2,12,13,16),

(2,3,4,8,9,10,11,2)

(2,3,4,8,9,11,2)

(2,3,4,5,6,8,9,10,11,2),

(2,3,4,5,6,8,9,11,2),

(4,5,7,4),

(4,5,6,7,4),

(13,14,15,13)

(15,13,14,15)}

基于Junit及Eclemma实现一个主路径覆盖的测试。

对于实验一的程序:

 1 package triangle;
 2
 3 public class Triangle {
 4     private int a,b,c;
 5
 6     public Triangle(int a, int b, int c) {
 7         super();
 8         this.a = a;
 9         this.b = b;
10         this.c = c;
11     }
12
13     public String judgeTriangle(){
14         if(a+b>c&&a+c>b&&b+c>a){
15             if(a==b&&a==c)return "equilLateral";
16             else if(a==b||a==c||b==c) return "isSosceles";
17             else return "scalene";
18         }
19         else return "notTriangle";
20     }
21 }
22 

31
32 public class TestCase {
33     Triangle t;
34     @Test
35     public void test(){
36         t = new Triangle(1,1,1);
37         assertEquals("equilLateral",t.judgeTriangle());
38         t = new Triangle(1,2,2);
39         assertEquals("isSosceles",t.judgeTriangle());
40         t = new Triangle(2,3,4);
41         assertEquals("scalene",t.judgeTriangle());
42         t = new Triangle(1,2,3);
43         assertEquals("notTriangle",t.judgeTriangle());
44     }
45 }
46  

测试用例(1,1,1),(1,2,2),(2,3,4),(1,2,3)可完成主路径覆盖。

时间: 2024-08-11 09:53:13

软件测试作业3:图覆盖的理解及应用的相关文章

软件测试(第三次作业)——图覆盖

(a) (b) 对于测试用例t1=(n=3)和t2=(n=5),MAXPRIMES = 4时,t1不能检查出错误,而t2则会发生数组越界错. (c) 对于测试用例t3=(n=1),测试路径不经过while的循环体. (d) 节点覆盖:TR={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18} 边覆盖:TR={(1,2), (2,3), (2,4), (3,5), (4,14), (5,6), (5,7), (6,8), (7,11), (7,12), (8

软件测试作业——Junit使用

软件测试作业--Junit使用 [TOC] 题目要求 Install Junit(4.12),Hamcrest(1.3) with Eclipse Install Eclemma with Eclipse Write a javaprogram for the triangle problem and test the program with Junit. Description oftriangle problem:Functiontriangle takes three integers

软件测试图覆盖

public static void printPrimes (int n) { int curPrime; int numPrimes; boolean isPrime; int [] primes = new int [MAXPRIMES]; primes [0] = 2; numPrimes = 1; curPrime = 2; while (numPrimes < n) { curPrime++; isPrime = true; for (int i = 0; i <= numPrim

软件测试作业——三

作业见<软件测试基础>中文版49页第7题.英文版63页 a) b) 令MAXPRIMES = 4,t1不能检查出错误,t2发生数组越界,使得t2比t1更容易发现. c)t3=(n=1) d)节点覆盖:TR={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16} 边覆盖:TR={(1,2),(2,3),(2,12),(3,4),(4,5),(5,6),(6,8),(8,5),(6,7),(7,9), (5,9),(9,10),(10,11),(9,11),(12,13)

第五次软件测试作业

构建指法心得体会 这是一次很特别的作业,对一本书做出的自己的心得体会,这是一本什么样的书本,对我而言,我也不太清楚,毕竟从开学到现在我大概就打开它两三次,也说不出这本书哪里好,但是所先,我拿起这本书,我习惯性看了这本书的目录,一览目录,觉得都是知识.都是新鲜的IT软件知识,关键我对IT感兴趣吗?如果我可以不打代码,我相信我会对IT之类的书本很感兴趣,有的人可以从打代码,做工程中得到成功的兴趣,而有的人只会这样说,总算好了,这个项目,这样就决定我自己是如何看待这本书了,不过知识毕竟是无价之宝,多一

软件测试的维恩图

软件测试主要关注的是程序行为,在程序所有可能的行为中,一部分是规格说明所描述的行为(用集合S表示),一部分是程序最终实现的行为(用集合P表示),图1显示了二者之间存在的关系.在这个维恩图中,有些规定的程序行为并没有被实现,我们称之为“遗漏缺陷”:有些实现的行为并不是规格说明中规定的,我们称之为“过失缺陷”:只有集合S和P相交的部分是“正确”的,即所实现的期望行为.那么,测试就是确定按规定实现的程序行为范围的过程. 图1   程序的期望行为与实现行为之间的关系 测试是通过测试用例来引发程序行为的,

什么?又是404!趣图助你理解HTTP状态码~

HTTP状态码(一):   注释: 301—永久移动.被请求的资源已被永久移动位置: 302—请求的资源现在临时从不同的 URI 响应请求: 305—使用代理.被请求的资源必须通过指定的代理才能被访问: 307—临时跳转.被请求的资源在临时从不同的URL响应请求: 400—错误请求: 402—需要付款.该状态码是为了将来可能的需求而预留的,用于一些数字货币或者是微支付: 403—禁止访问.服务器已经理解请求,但是拒绝执行它: 404—找不到对象.请求失败,资源不存在: 406—不可接受的.请求的

软件测试作业三-printPrimes()

作业内容: private static void printPrimes(int n) { int curPrime; int numPrimes; boolean isPrime; int MAXPRIMES=50; int [] primes = new int [MAXPRIMES]; primes [0] = 2; numPrimes = 1; curPrime = 2; while (numPrimes < n) { curPrime++; isPrime = true; for (

软件测试--作业四

<软件测试>第四次作业 1.某公司网站的后台管理有一个用户注册的功能需要测试,该测试为黑盒测试,请用表格的方式给出该功能的测试用例(参考课本P107页).用户注册功能描述如下: (1)       管理员必须先登录,方可进入网站后台管理,进入后台管理界面后可以进行用户注册(假设用户注册的URL地址为http://www.fengt.com/Admin/UserRegister.jsp) (2)       用户注册要求输入用户名.密码.密码确认.邮箱,这4项内容均不能为空 (3)