软件测试实验报告梁振兴_第1页
软件测试实验报告梁振兴_第2页
软件测试实验报告梁振兴_第3页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、广州大学学生实验报告开课学院及实验室:计算机科学与工程实验室418 2013年 05月 3日学院计算机科学与教育软件学院年级/专业/班软工104姓名曾帆学号1006100012实验课程名称软件测试成绩实验项目名称JUnit测试框架的使用指导老师田际平(*报告只能为文字和图片,老师评语将添加到此处,学生请勿作答*)一、实验目的1、掌握Junit测试框架的使用2、掌握测试用例的编写二、实验内容1、熟悉java编程语言和Eclipse集成开发环境2、熟悉单元测试概念3、熟悉测试设计技术三、实验原理1、学习Junit框架的使用A、Junit使用方法示例11)把Junit引入当前项目库中新建一个 Jav

2、a 工程coolJUnit,打开项目coolJUnit 的属性页 - 选择“Java Build Path”子选项 - 点选“Add Library”按钮 - 在弹出的“Add Library”对话框中选择 JUnit,并在下一页中选择版本 Junit 4 后点击“Finish”按钮。2)新建单元测试代码目录在项目 coolJUnit 根目录下添加一个新目录 testsrc,并把它加入到项目源代码目录中。3)在工程中添加类添加类SampleCaculator,类中有两个方法,分别计算加减法,编译代码。4)写单元测试代码为类SampleCalculator添加测试用例。在资源管理器SampleC

3、alculator.java文件处右击选new选Junit Test Case,Source foler选择testsrc目录,点击next,选择要测试的方法,这里把add和subtration方法都选上,最后点finish完成,Junit自动生成测试类SampleCalculatorTest。5)查看运行结果在测试类上点击右键,在弹出菜单中选择 Run As JUnit Test。运行结果为绿色的进度条则测试运行通过了。B、Junit使用方法示例21)在工程中添加类类WordDealUtil中的方法wordFormat4DB( )实现的功能见文件注释。2)写单元测试代码3)进一步完善测试用例

4、单元测试的范围要全面,如对边界值、正常值、错误值的测试。运用所学的测试用例的设计方法,如:等价类划分法、边界值分析法,对测试用例进行进一步完善。4)查看分析运行结果,修改错误代码再次运行测试。JUnit 运行界面提示我们有两个测试情况未通过测试,当首字母大写时得到的处理结果与预期的有偏差,造成测试失败(failure);而当测试对 null 的处理结果时,则直接抛出了异常测试错误(error)。2、使用Junit框架对类Date和类DateUtil进行单元测试。对包含业务逻辑的方法进行测试,包括:类DateisDayValid(int year, int month, int day)isMo

5、nthValid(int month)isYearValid(int year)类DateUtilisLeapYear(int year)getDayofYear(Date date)设计合理测试用例,用Junit进行测试,分析测试结果,并对错误代码进行修改。四、实验设备windows操作系统+IE浏览器Eclipse集成开发环境+Junit测试框架五、实验要求做好实验预习,掌握并熟悉本实验中所使用的测试环境及相应的测试软件。写出实验报告,完成实验内容2,给出测试用例,分析测试结果,给出改进后的代码。六、实验程序测试用例DateTest:package .gzhu;import s

6、tatic org.junit.Assert.*;import org.junit.Test;public class DateTest public Date date = new Date();/*isDayValid()的各种测试*/Testpublic void testIsDayValid()String year = -589;String month = -96;String day = -3;boolean result = date.isDayValid(year, month, day);assertFalse(result);Testpublic void testIsD

7、ayValidLeapYear() String year = 2012;String month = 2;String day = 29;boolean result = date.isDayValid(year, month, day);assertEquals(true,result);Testpublic void testIsDayValidIllgal() String year = 010;String month = 005;String day = 003;boolean result = date.isDayValid(year, month, day);assertFal

8、se(result);Testpublic void testIsDayValidNull()String year = null;String month = null;String day = null;boolean result = date.isDayValid(year, month, day);assertFalse(result);Testpublic void testIsDayValidEmpty()String year = ;String month = ;String day = ;boolean result = date.isDayValid(year, mont

9、h, day);assertFalse(result);/*isMonthValid()的各种测试*/Testpublic void testIsMonthValid() String month = 8;boolean result = date.isMonthValid(month);assertEquals(true, result);Testpublic void testIsMonthValidIllegal() String month = 010;boolean result = date.isMonthValid(month);assertFalse(result);Testp

10、ublic void testIsMonthValidLess() String month = -3;boolean result = date.isMonthValid(month);assertFalse(result);Testpublic void testIsMonthValidMore() String month = 19;boolean result = date.isMonthValid(month);assertFalse(result);Testpublic void testIsMonthValidNull() String month = null;boolean

11、result = date.isMonthValid(month);assertFalse(result);Testpublic void testIsMonthValidEmpty() String month = ;boolean result = date.isMonthValid(month);assertFalse(result);/*isYearValid()的各种测试*/Testpublic void testIsYearValid() String year = 145;boolean result = date.isYearValid(year);assertEquals(t

12、rue,result);Testpublic void testIsYearValidIllegal() String year = 010;boolean result = date.isYearValid(year);assertFalse(result);Testpublic void testIsYearValidLess() String year = -3;boolean result = date.isYearValid(year);assertFalse(result);Testpublic void testIsYearValidNull() String year = nu

13、ll;boolean result = date.isMonthValid(year);assertFalse(result);Testpublic void testIsYearValidEmpty() String year = ;boolean result = date.isMonthValid(year);assertFalse(result);改进后的Date类:package .gzhu;public class Date public Date() public Date(String year, String month, String day) super();

14、if (this.isDayValid(year, month, day) & this.isMonthValid(month)& this.isYearValid(year) this.year = Integer.parseInt(year);this.month = Integer.parseInt(month);this.day = Integer.parseInt(day); else throw new IllegalArgumentException(Please check your input!);/* * 0 year */private int year = -1;/*

15、* 1 = month = 12 */private int month = -1;/* * 1 = day =31 the day should in the scope 1, 30 when the month is: 4, * 6, ,9, 11 the day should in the scope 1, 31 when the month is: 1, 3, 5, * 7, 8, 10, 12 the day should in the scope 1, 28 when the month is 2 and * the year is not leap year see the da

16、y should in the scope 1, 29 when * the month is 2 and the year is leap year see */private int day = -1;public boolean isDayValid(String year, String month, String day) int y, m, d;if(year = null | month = null | day = null)return false;if(year.isEmpty() | month.isEmpty() | day.isEmpty()return false;

17、if(year.charAt(0) != 0 & month.charAt(0) != 0 & day.charAt(0) != 0)y = Integer.parseInt(year);m = Integer.parseInt(month);d = Integer.parseInt(day);if (m = 4 | m = 6 | m = 9 | m = 11) & (d = 1)return true;if (m = 4 | m = 6 | m = 9 | m = 11) & (d 30 | d 1)return false;if (m = 1 | m = 3 | m = 5 | m =

18、7 | m = 8 | m = 10 | m = 12)& (d = 1)return true;if (m = 1 | m = 3 | m = 5 | m = 7 | m = 8 | m = 10 | m = 12)& (d 31 | d = 1 & d = 29)return true;if (m = 2 & DateUtil.isLeapYear(y) & (d 29)return false;if (m = 2 & !DateUtil.isLeapYear(y) & (d = 1 & d = 28)return true;if (m = 2 & !DateUtil.isLeapYear

19、(y) & (d 28)return false;return false;public boolean isMonthValid(String month) if(month = null | month.isEmpty()return false;if (month.charAt(0) != 0) return Integer.parseInt(month) = 1& Integer.parseInt(month) 0;return false;public int getYear() return year;public void setYear(String year) if (this.isYearValid(year) this.year = Integer.parseInt(year); else throw new IllegalArgumentException(Please check your input!);public int getMonth() return month;public void setMonth(String month) if (this.isMonthValid(month) this.month = Integer.parseInt(month); else t

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论