




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上实验报告实验序号:02实验项目名称:基本路径测试法和单元测试工具JUnit的使用学号姓名曹锋专业、班09软件工程一班实验地点1#316指导教师崔建峰实验时间2012/3/5一、实验目的l 掌握基本路径测试方法;l 了解在Eclipse环境下JUnit单元测试工具的安装和使用方法;l 针对一个实际问题,在JUnit环境下设计并执行测试用例。二、实验要求l 开发环境:Eclipse v3.7及以上版本;JUnit v4.10及以上版本;文本编辑软件。 l 硬件要求:CPU PIV 以上,256M 内存,1G 硬盘空间。l 系统要求:Windows98/Me/XP/NT/2
2、000,IE 5 以上。三、实验内容与步骤1. 下载并安装JDK+Eclipse,学习Eclipse安装与使用方法。2. 下载并安装JUnit,学习JUnit安装与使用方法。3. 通读自动售货机程序,并将其在Eclipse环境下运行。问题描述,程序流程图和程序源代码见附录。4. 按照如下格式,采用基本路径测试法编写测试用例(要有程序流程控制图,基本路径)。编号输入值Type输入值money状态预输出实际情况1Beer5C各资源剩余Input Information Type: Beer; Money: 5 Cents; Change: 0Current StateBeer: 5Orange J
3、uice: 65 Cents: 71 Dollar: 6与预期相同2OrangeJuice5C各资源剩余Input Information Type: OrangeJuice; Money: 5 Cents; Change: 0Current StateBeer: 6Orange Juice: 55 Cents: 71 Dollar: 6与预期相同3Beer5C没有啤酒Filure InformationBeer Shortage与预期相同4OrangeJuice5C没有橙汁Failure InformationOrangeJuice Shortage与预期不同5Cola5C各资源剩余Fail
4、ure InformationType Error与预期相同6Beer1D没啤酒Failure InformationBeer Shortage与预期不同7Beer1D各资源剩余Input Information Type: Beer; Money: 1 Dollar; Change:5 CentsCurrent StateBeer: 5Orange Juice: 65 Cents: 51 Dollar: 7与预期不同8OrangeJuice1D各资源剩余Input Information Type: OrangeJuice; Money: 1 Dollar; Change: 5 CentsC
5、urrent StateBeer: 6Orange Juice: 55 Cents:51 Dollar: 7与预期不同9OrangeJuice1D没有橙汁Failure InformationOrangeJuice Shortage与预期不同10Cola1D各资源剩余Failure InformationType Error与预期相同11Beer1D没有5角Failure InformationChange Shortage与预期不同12OrangeJuice4C各资源剩余Failure InformationMoney Error与预期相同5. 编写并执行基于JUnit的测试用例。6. 提交
6、测试用例程序和该程序运行结果最终画面。7. 总结本次试验,并撰写实验报告。程序流程图如图一所示:(流程图可复制粘贴到画图查看大图。)图一实验截图:编写完测试用例,运行程序,源程序有六个错误,如图二所示:图二根据相应错误修改代码后测试通过,如图三所示:图三四、分析与讨论 通过此次实验,我初步学会了测试工具Junit的使用方法,发现使用测试工具可以给程序测试带来很大的方便,使我们更容易找到程序的错误。五、教师评语签名:日期:成绩程序源代码:修改后的代码:package first;public class SaleMachine private int countOfBeer, countOfOr
7、angeJuice, 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
8、, 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: + cou
9、ntOfFiveCents + 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 Informat
10、ion 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
11、 + 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(countO
12、fFiveCents0) /如果用户投入一元钱/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.equa
13、ls(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 =
14、 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 Infor
15、mation n + Change Shortage;return resultOfDeal;/else/resultOfDeal = Failure Information n + Money Error;/return resultOfDeal;/resultOfDeal = Failure Information n + Money Error;return resultOfDeal;测试用例代码:package first;import junit.framework.TestCase;public class TestSaleMachine extends TestCase publ
16、ic void testOperation1() /售货机各资源均有剩余,用户投币5角,选择啤酒SaleMachine saleMachine1 = new SaleMachine();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, saleMachine1.operation(
17、Beer, 5C);public void testOperation2()/售货机没有啤酒剩余,用户投币5角,选择啤酒SaleMachine saleMachine2 = new SaleMachine(6,6,0,6);String expectedResult = Failure Information n + Beer Shortage;assertEquals(expectedResult,saleMachine2.operation(Beer, 5C);public void testOperation3() /售货机各资源均有剩余,用户投币5角,选择橙汁SaleMachine s
18、aleMachine3 = new SaleMachine();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, saleMachine3.operation(OrangeJuice, 5C);public void testOperation4()/售货机没有橙汁,
19、用户投币5角,选择橙汁SaleMachine saleMachine4 = new SaleMachine(6,6,6,0);String expectedResult = Failure Information n + OrangeJuice Shortage;assertEquals(expectedResult,saleMachine4.operation(OrangeJuice, 5C);public void testOperation5()/用户投入5角,选择非啤酒非橙汁SaleMachine saleMachine5 = new SaleMachine(6,6,6,6);Stri
20、ng expectedResult = Failure Information n + Type Error;assertEquals(expectedResult,saleMachine5.operation(Cola, 5C);public void testOperation6()/售货机有啤酒且有5角币,用户投币1元,选择啤酒SaleMachine saleMachine6 = new SaleMachine(6,6,6,6);String expectedResult = Input Information n +Type: Beer; Money: 1 Dollar; Change
21、: 5 Centsnn +Current Staten +Beer: 5n +Orange Juice: 6n +5 Cents: 5n +1 Dollar: 7;assertEquals(expectedResult,saleMachine6.operation(Beer, 1D);public void testOperation7() /售货机没有啤酒有5角,用户投币1元,选择啤酒SaleMachine saleMachine7 = new SaleMachine(6,6,0,6);String expectedResult = Failure Information n + Beer
22、Shortage;assertEquals(expectedResult, saleMachine7.operation(Beer, 1D);public void testOperation8()/售货机有橙汁且有5角币,用户投币1元,选择橙汁SaleMachine saleMachine8 = new SaleMachine(6,6,6,6);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,saleMachine8.operation(OrangeJuice, 1D);public void testOperation9()/售货机有5角没有橙汁,用户投币1元,选择橙汁SaleMachine saleMachine9 = new SaleMachine(6,6,6,0);String expectedResult = Failure Information n + OrangeJu
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 流量封顶解封协议书
- 收购技术团队协议书
- 机井产权转让协议书
- 村民道路修缮协议书
- 油茶基地收购协议书
- 旅游营销推广协议书
- 机械加工制造协议书
- 民建支部结对协议书
- 收购工厂废铁协议书
- 木材山林转让协议书
- 2024年广西物流职业技术学院招聘教职人员笔试真题
- 2024-2025湘科版小学科学四年级下册期末考试卷及答案(三套)
- 中国企业科创力研究报告2024
- 大型海上发电用双燃料燃气轮机企业数字化转型与智慧升级战略研究报告
- 工程承包再转让合同协议
- (广东二模)2025年广东省高三高考模拟测试(二)历史试卷(含答案)
- 2025湖南建投集团春季校园招聘239人笔试参考题库附带答案详解
- 2025-2030全球冰雪产业经营效益与发展投资策略建议研究报告
- 反邪教测试题及答案
- 业务合规制度培训
- GB/T 14601-2025电子特气氨
评论
0/150
提交评论