软件测试作业3

1.为printPrimes()方法画控制流图:

 

 

2.设计测试用例使得t2比t1更容易发现:

令MAXPRIMES=4,运行t2会数组越界而t1不会。

3.设计测试用例使得相应测试路径不经过while循环体:

需满足numPrimes>n,可令n=1。

4.列举节点覆盖,边覆盖,主路径覆盖的测试需求:

节点覆盖:{1 , 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};

边覆盖:{(1,2),(2,3),(3,4),(4,5),(5,6),(6,8),(8,5),(6,7),(7,9),(5,9),

(9,10),(9,11),(10,11),(11,2),(2,12),(12,13),(13,14),(14,15),(15,13),(13,16)};

主路径覆盖:{(1,2,3,4,5,6,8),(1,2,3,4,5,6,7,9,10,11),(1,2,3,4,5,6,7,9,11),

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

(8,5,6,7,9,11),(8,5,6,7,9,10,11),(1,2,12,13,16),(1,2,12,13,14,15),(13,14,15,13),

(14,15,13,14),(15,13,14,15),(14,15,13,16),(15,13,16)}。

5.基于JunitEclemmajacoco)实现一个主路径覆盖的测试。
编写测试类和被测试类:

MPCtest.java:

package hm3;

public class MPCtest {
private static final int MAXPRIMES = 100;

public 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 <= numPrimes-1 ;i++){
if (isDivisible(primes[i],curPrime))
{
isPrime = false;
break ;
}
}
if (isPrime){
primes[numPrimes] = curPrime ;
numPrimes ++ ;

}
}

for (int i = 0 ; i <= numPrimes -1 ; i++ )
{
System.out.println("Prime: " + primes[i]);
}

}

private boolean isDivisible(int x, int y ) {
if ( y % x == 0 )
return true;
else
return false;
}

}

 

Junit_test.java:

package hm3;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class Junit_test {
private MPCtest t= null;

@Before
public void setUp() throws Exception {
t = new MPCtest();
}

@Test
public void test() {
t.printPrimes(5);
}
}

 

测试结果截图:

 

 

 

转载于:https://www.cnblogs.com/mkz321/p/8650152.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值