1、1湖北科技学院软件测试实验报告课程名称 软件测试方法与技 术 班级 实验日期姓名 学号 实验成绩实验名称 白盒测试实验实验目的与要求(1)掌握白盒测试技术,并能应用白盒测试技术设计测试用例(2)能用 Junit 实施测试实验环境主流 PC 机一套,需安装 windows 操作系统、Office 、Eclipse 和 Junit实验内容题目一:用逻辑覆盖测试方法测试以下程序段void DoWork (int x,int y,int z)1 int k=0, j=0;2 if ( (x3)9 j=j%3;10 说明:程序段中每行开头的数字(110)是对每条语句的编号。(1)画出程序的控制流图(用题
2、中给出的语句编号表示)。(2)分别以语句覆盖、判定覆盖、条件覆盖、判定/条件覆盖、组合覆盖和路径覆盖方法设计测试用例,并写出每个测试用例的执行路径(用题中给出的语句编号表示)。题目二、折半查找请按要求对下面的 java 代码进行测试。代码的功能是:用折半查找法在2元素呈升序排列的数组中查找值为 key 的元素。public int binSearch ( int array, int key ) int mid, low, high;low = 0;high = array.length-1;while ( low 32.low = 0;3.high = array.length-1;4.wh
3、ile ( low 3) j=j%3;public boolean doWork(int x,int y,int z)return true;测试程序:(1)package gy.test2;import junit.framework.*;import org.junit.Test;public class DoWorkTest1 extends TestCase private static int x,y,z;private static DoWork dowork=new DoWork(x,y,z);public void setUp() throws Exception Testpu
4、blic void testDoWork() assertEquals(true, dowork.doWork(4, 8, 8);(2)package gy.test2;import static org.junit.Assert.*;11import org.junit.Test;public class DoWorkTest2 private static int x,y,z;private static DoWork dowork=new DoWork(x,y,z);public void setUp() throws Exception Testpublic void testDoWo
5、rk() assertEquals(true, dowork.doWork(4, 3, 13);(3)package gy.test2;import static org.junit.Assert.*;import org.junit.Test;public class DoWorkTest3 private static int x,y,z;private static DoWork dowork=new DoWork(x,y,z);public void setUp() throws Exception Testpublic void testDoWork() assertEquals(t
6、rue, dowork.doWork(6, 2, 8);12(4)package gy.test2;import static org.junit.Assert.*;import org.junit.Test;public class DoWorkTest4 private static int x,y,z;private static DoWork dowork=new DoWork(x,y,z);public void setUp() throws Exception Testpublic void testDoWork() assertEquals(true, dowork.doWork
7、(2, 3, 13);2.源程序:package gy.test;public class BinSearch public int binSearch (int array,int key) int mid,low,high;low = 0;high = array.length-1;while (low = high) 13mid = (low+high)/2;if (key = arraymid)return mid;else if (key array mid)high = mid -1;elselow = mid+1;return -1;测试程序:(1)package gy.test
8、;import junit.framework.*;public class BinSearchTest1 extends TestCaseprivate static BinSearch search= new BinSearch();private int array = ;public void setUp() throws Exception public void testBinSearch() assertEquals(-1, search.binSearch(array, 1); (2)package gy.test;import junit.framework.*;public
9、 class BinSearchTest2 extends TestCase private static BinSearch search= new BinSearch();private int array = 2,4,6;public void setUp() throws Exception 14public void testBinSearch() assertEquals(1, search.binSearch(array, 4);(3)package gy.test;import junit.framework.*;public class BinSearchTest3 exte
10、nds TestCaseprivate static BinSearch search= new BinSearch();private int array = 2,4,6,8;public void setUp() throws Exception public void testBinSearch() assertEquals(0, search.binSearch(array, 2);(4)package gy.test;import junit.framework.*;public class BinSearchTest4 extends TestCase 15private static BinSearch search= new BinSearch();private int array = 2,4,6,8;public void setUp() throws Exception public void testBinSearch() assertEquals(2, search.binSearch(array, 6);