(1)流程图
(2)会发生数组越界问题
(3)比如当n=10时,会跳过while循环
(4)
点覆盖包括{1,2,3,4,5,6,7,8,9,10,11}
边覆盖:{(1,2),(2,3),(2,8),(3,4),(5,4),(5,6),(6,2),(7,2),(8,9),(9,10),(10,9)(9,11)}
主路径覆盖:{(1,2,3,4,5,6,7),(2,3,4,5,6,2),(2,3,4,5,6,7,2),(7,2,8,9,10),(7,2,8,9,11),(7,2,3,4,5,6,7),(1,2,8,9,10),(1,2,8,9,11),(6,2,3,4,5,6),(4,5,6,7,2,3,4),(4,5,6,7,2,3,4),(4,5,4),(5,4,5),(9,10,9),(10,9,10),(10,9,11)}
使用第一次试验项目三角形,测试主路径覆盖的测试。
package com.junit_test_lab1; public class TestTriangle { public static String getKind(int a,int b,int c){ if(a+b<c||a+c<b||b+c<a){ return "不是三角形"; }else if(a==b&&a==c&&b==c){ return "等边三角形"; }else if(a==b||b==c||a==c){ return "等腰三角形"; }else{ return "普通三角形"; } } }
import static org.junit.Assert.*; import java.util.Arrays; import java.util.Collection; import org.junit.*; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class Triangle_test { private int a,b,c; private String str =null; public Triangle_test(int a,int b, int c,String str) { this.a=a; this.b=b; this.c=c; this.str=str; } @Parameters public static Collection<Object[]> getData(){ return Arrays.asList(new Object[][]{ {1,2,2,"不是三角形"}, {2,2,5,"等腰三角形"}, {3,3,3,"等边三角形"}, {3,8,10,"普通三角形"}, }); } @Test public void test() { assertEquals(this.str,triangle.triangle_shape(a,b,c)); } }
使用代码所示的测试用例实现了主路径覆盖