软件测试第三次作业junit和Eclemma的使用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了软件测试第三次作业junit和Eclemma的使用相关的知识,希望对你有一定的参考价值。
1.
2.将第20行
for(int i = 0; i<=numPrimes-1;i++)
改为
for(int i = 0; i<numPrimes-1;i++)
3.n=2
4.节点覆盖:
[0,1,2,3,5,3,4,6,7,8,9,10,11]
边覆盖
[0,1,2,3,5,3,4,6,7,8,9,10,9,10,11]
[0,1,2,3,4,7,1,2,3,4,7,8,9,10,11]
主路径覆盖:
[0,1,2,3,5,3,5,3,4,6,7,1,2,3,4,7,1,2,3,4,6,7,1,2,3,4,6,7,8,9,10,9,10,11]
[0,1,2,3,4,6,7,8,9,10,11]
[0,1,2,3,4,7,8,9,10,11]
5.主路进测试junit和Eclemma
(一)修改部分程序,方便测试
修改前:
package hw3;
public class hw3code {
private static void printPrimes(int n){
int curPrime;
int numPrimes;
boolean isPrime;
int MAXPRIMES = 100;
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]);
}
}
static boolean isDivisible(int x, int y){
int a = y/x;
double b = (double)y/(double)x;
// System.out.println(a);
// System.out.println(b);
if(b-a == 0){
return true;
}
else{
return false;
}
}
}
修改后
package hw3;
import java.util.Arrays;
public class hw3change {
static int[] printPrimes(int n){
int curPrime;
int numPrimes;
boolean isPrime;
int [] Primes = new int[n];
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]);
}
return Primes;
}
static boolean isDivisible(int x, int y){
int a = y/x;
double b = (double)y/(double)x;
// System.out.println(a);
// System.out.println(b);
if(b-a == 0){
return true;
}
else{
return false;
}
}
}
(二)确定测试路径对应的n值
其中path1为n=5;
Path2 为 n = 2;
Path3 在实际上不可能发生;
所以测试程序为
package hw3;
import static org.junit.Assert.*;
import org.junit.Test;
public class hw3changeTest {
hw3change pri = new hw3change();
@Test
public void testprimepath2() {
int right[] = {2,3};
assertArrayEquals(right,pri.printPrimes(2));
}
@Test
public void testprimepath1() {
int right[] = {2,3,5,7,11};
assertArrayEquals(right,pri.printPrimes(5));
}
}
Junit结果:
Eclemma结果:
其中对应该程序为hw3change.java和hw3changeTest.java.
以上是关于软件测试第三次作业junit和Eclemma的使用的主要内容,如果未能解决你的问题,请参考以下文章