文档介绍:[软件测试实验报告 ] 计算机 2010-1 姓名:周杰 学号: 3100717102
JUnit 测试框架的使用
【实验目的】
1、掌握 Junit 测试框架的使用
2、掌握测试用例的编写
【实验环境】
操作系统: Windows 7 ( x64)
浏览器: IE 9
开发环境: Eclipse IDE for Java Developers
A : Junit 使用方法示例 1
查看运行结果:
B: Junit 使用方法示例 2
1)在工程中添加类:
2)写单元测试代码:
3)进一步完善测试用例:
4)查看分析运行结果,修改错误代码:
改进后的方法:
wordFormat4DB
public static String wordFormat4DB(String name){
if(name == null){
return null;
}
Pattern p = ("[A-Z]");
Matcher m = (name);
StringBuffer sb = new StringBuffer();
while(()){
if(() != 0)
(sb, ("_"+()).toLowerCase());
}
return (sb).toString().toLowerCase();
}
修改后测试用例运行成功:
实验 2
【实验目的】
1、掌握 Junit 测试框架的使用
2、掌握测试用例的编写
【实验环境】
操作系统: Windows 7 ( x64)
浏览器: IE 9
开发环境: Eclipse IDE for Java Developers
【程序清单】
package zhoujie;
public class Date {
public Date() {
}
public Date(int year, int month, int day) {
super();
if ((year, month, day) && (month)
(year)) { = year;
= month;
= day;
}else{
throw new IllegalArgumentException("Please check your input!"); }
}
private int year = -1;
private int month = -1;
private int day = -1;
public boolean isDayValid(int year, int month, int day) {
if ((month == 4 || month == 6 || month == 9 || month == 11) && (day <= 30 && day >= 1))
return true;
if ((month == 4 || m