




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验报告实验序号:04 实验项目名称:使用基本路径测试法求解 “自动售货机”问题学号122姓名专业、班实验地点实1-511指导教师实验时间2013/4/27一、实验目的及要求l 理解基本路径覆盖测试法的概念和方法;l 掌握使用Eclipse+JUnit+EclEmma进行基本路径覆盖测试的方法。二、实验设备(环境)及要求l 开发环境:Eclipse v3.7及以上版本;JUnit v4.10及以上版本;文本编辑软件。 l 硬件要求:CPU PIV 以上,256M 内存,1G 硬盘空间。l 系统要求:Windows98/Me/XP/NT/2000,IE 5 以上。三、实验内容步骤1. 下载并安装Eclipse+JUnit+EclEmma实验环境;2. 通读自动售货机程序,并在Eclipse环境下运行该程序;3. 使用基本路径测试法设计测试用例,完成以下表格;编号输入值Type输入值money状态预期输出实际情况001Beer5C各资源剩余Input Information Type: Beer; Money: 5 Cents; Change: 0Current StateBeer: 5Orange Juice: 65 Cents: 71 Dollar: 6002OrangeJuice5C各资源剩余Input Information Type: OrangeJuice; Money: 5 Cents; Change: 0Current StateBeer: 6Orange Juice: 55 Cents: 71 Dollar: 6003Beer1D没有啤酒Failure InformationBeer Shortage步骤:1、解压eclemma软件包,并放到eclipse安装目录的dropins文件夹下:2、重新启动eclipse软件,菜单栏会出现新的图标:3、查看Windows的Customize perspective项中的Command Groups Availabiity 多了Coverage项:4、编写待测试类SaleMachine.java文件和测试Junit Test Case文件SaleMachineTest.java:5、先点击运行看看,覆盖了33.1%:6、分析:红色代表未执行、黄色代表条件没有全部执行、绿色代表执行过了:7、继续修改测试代码,直到覆盖率达到100%:共编写了12个测试用例,使待测试代码100%被覆盖,运行如图:四、实验结果与数据处理a、最终待测试代码如下:public class SaleMachine private int countOfBeer, countOfOrangeJuice, countOfFiveCents, countOfOneDollar;private String typeOfGoods = Beer, OrangeJuice;private String resultOfDeal;public SaleMachine()initial();public void initial()countOfBeer = 6;countOfOrangeJuice = 6;countOfFiveCents = 6;countOfOneDollar = 6;public SaleMachine(int fiveCents, int oneDollar, int numOfBeer, int numOfOrange)/便于测试的初始化函数countOfFiveCents = fiveCents;countOfOneDollar = oneDollar;countOfBeer = numOfBeer;countOfOrangeJuice = numOfOrange;public String currentState()String state = Current Staten + Beer: + countOfBeer + n + Orange Juice: + countOfOrangeJuice + n + 5 Cents: + countOfFiveCents + n + 1 Dollar: + countOfOneDollar;return state;public String operation(String type, String money)/type是用户选择的产品,money是用户投币种类if(money.equalsIgnoreCase(5C) /如果用户投入5角钱if(type.equals(typeOfGoods0) /如果用户选择啤酒if(countOfBeer0) /如果还有啤酒countOfBeer-;countOfFiveCents+;resultOfDeal = Input Information n + Type: Beer; Money: 5 Cents; Change: 0nn + currentState();return resultOfDeal;elseresultOfDeal = Failure Information n + Beer Shortage;return resultOfDeal;else if (type.equals(typeOfGoods1) /用户选择橙汁if(countOfOrangeJuice 0)countOfOrangeJuice-;countOfFiveCents+;resultOfDeal = Input Information n + Type: OrangeJuice; Money: 5 Cents; Change: 0nn + currentState();return resultOfDeal;elseresultOfDeal = Failure Information n + OrangeJuice Shortage;return resultOfDeal;elseresultOfDeal = Failure Information n + Type Error;return resultOfDeal;else if(money.equalsIgnoreCase(1D) /如果用户投入一元钱/if(countOfFiveCents0) /如果用户投入一元钱/if(countOfFiveCents 0) /如果售货机有零钱if(type.equals(typeOfGoods0)&countOfBeer0)/如果用户选择啤酒而且还有啤酒countOfBeer-;countOfFiveCents-;countOfOneDollar+;resultOfDeal = Input Information n + Type: Beer; Money: 1 Dollar; Change: 5 Centsnn + currentState();return resultOfDeal;else if (type.equals(typeOfGoods1)&countOfOrangeJuice0)/如果用户选择橙汁而且还有橙汁countOfOrangeJuice-;countOfFiveCents-;countOfOneDollar+;resultOfDeal = Input Information: n + Type: OrangeJuice; Money: 1 Dollar; Change: 5 Centsnn + currentState();return resultOfDeal;elseif(type.equals(typeOfGoods0)&countOfBeer=0) resultOfDeal = Failure Information n + Beer Shortage;return resultOfDeal;else if(type.equals(typeOfGoods1)&countOfOrangeJuice=0)resultOfDeal = Failure Information n + OrangeJuice Shortage;return resultOfDeal;elseresultOfDeal = Failure Information n + Type Error;return resultOfDeal;elseresultOfDeal = Failure Information n + Change Shortage;return resultOfDeal;/*elseresultOfDeal = Failure Information n + Money Error;return resultOfDeal;*/resultOfDeal = Failure Information n + Money Error;return resultOfDeal;b、最终测试代码如下:import static org.junit.Assert.*;import org.junit.After;import org.junit.Before;import org.junit.Test;public class SaleMachineTest SaleMachine saleMachine = new SaleMachine();Beforepublic void setUp() throws Exception Afterpublic void tearDown() throws Exception Testpublic void testOperation1() String expectedResult = Input Information n +Type: OrangeJuice; Money: 5 Cents; Change: 0nn +Current Staten +Beer: 6n +Orange Juice: 5n +5 Cents: 7n +1 Dollar: 6;assertEquals(expectedResult, saleMachine.operation(OrangeJuice, 5C);Testpublic void testOperation2() String expectedResult = Input Information n +Type: Beer; Money: 5 Cents; Change: 0nn +Current Staten +Beer: 5n +Orange Juice: 6n +5 Cents: 7n +1 Dollar: 6;assertEquals(expectedResult, saleMachine.operation(Beer, 5C);Testpublic void testOperation3() SaleMachine saleMachine = new SaleMachine(6,6,0,6);String expectedResult = Failure Information n +Beer Shortage;assertEquals(expectedResult, saleMachine.operation(Beer, 5c);Testpublic void testOperation4() SaleMachine saleMachine = new SaleMachine(6,6,6,0);String expectedResult = Failure Information n +OrangeJuice Shortage;assertEquals(expectedResult, saleMachine.operation(OrangeJuice, 5c);Testpublic void testOperation5() SaleMachine saleMachine = new SaleMachine(6,6,6,6);String expectedResult = Failure Information n +Type Error;assertEquals(expectedResult, saleMachine.operation(apple, 5c);Testpublic void testOperation6() String expectedResult = Input Information n +Type: Beer; Money: 1 Dollar; Change: 5 Centsnn +Current Staten +Beer: 5n +Orange Juice: 6n +5 Cents: 5n +1 Dollar: 7;assertEquals(expectedResult, saleMachine.operation(Beer, 1D);Testpublic void testOperation7() String expectedResult = Input Information: n +Type: OrangeJuice; Money: 1 Dollar; Change: 5 Centsnn +Current Staten +Beer: 6n +Orange Juice: 5n +5 Cents: 5n +1 Dollar: 7;assertEquals(expectedResult, saleMachine.operation(OrangeJuice, 1D);Testpublic void testOperation8() SaleMachine saleMachine = new SaleMachine(6,6,0,6);String expectedResult = Failure Information n +Beer Shortage;assertEquals(expectedResult, saleMachine.operation(Beer, 1D);Testpublic void testOperation9() SaleMachine saleMachine = new SaleMachine(6,6,6,6);String expectedResult = Failure Information n +Type Error;assertEquals(expectedResult, saleMachine.operation(apple, 1D);Testpublic void testOperation10() SaleMachine saleMachine = new SaleMachine(6,6,6,0);String expectedResult = Failure Information n +Orang
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 IEC 62087-5:2015 RU Audio,video,and related equipment - Determination of power consumption - Part 5: Set-top-boxes
- 【正版授权】 IEC 60287-2-2:1995 FR-D Electric cables - Calculation of the current rating - Part 2: Thermal resistance - Section 2: A method for calculating reduction factors for groups o
- 【正版授权】 IEC 60245-3:1994/AMD1:1997 FR-D Amendment 1 - Rubber insulated cables - Rated voltages up to and including 450/750 V - Part 3: Heat resistant silicone insulated cables
- 娱乐产业消费者行为研究数据表
- 财务状况月度报表
- 医药领域党建考试试题及答案
- 六一售后活动方案
- 六一小班美食节活动方案
- 医学技能考试试题及答案
- 六一活动剧透活动方案
- 《基于核心素养的中学数学探究式教学研究》2300字(论文)
- 四川省成都市2023-2024学年六年级上学期语文期末试卷(含答案)
- 2024精神堡垒制作安装合同
- 江苏省苏州市2023-2024学年高二年级下学期学业质量阳光指标调研卷暨6月期末考试+地理试卷
- 化工公司安全知识竞赛题库(共1000题)
- 首都经济贸易大学管理信息系统期末考试试卷
- 有机化学(下)(华东理工大学)智慧树知到答案2024年华东理工大学
- DLT 572-2021 电力变压器运行规程
- DL∕T 1430-2015 变电设备在线监测系统技术导则
- 光伏项目系统调试方案
- AQ/T 1089-2020 煤矿加固煤岩体用高分子材料(正式版)
评论
0/150
提交评论