软件测试实验报告2
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
软件测试实验报告
题目名称:计算下一天时间测试
专业班级:软件三班
学号: 041140338 姓名:王超
一、实验综述
1、实验目的及要求
实验目的:
掌握等价类测试方法的原理及使用。
实验要求:
(1)完成各个程序的编写
(2)按要求设计测试用例,并运行测试用例检查程序的正确与否
实验内容:
对日期操作函数进行等价类测试方法的测试用例设计及测试结果记录与分析。
2、实验仪器、设备或软件
1. 个人计算机PC;
2. VisualC++/.NET编程环境。
二、实验过程(实验步骤、记录、数据、分析)
1.程序有三个变量(月份、日期、和年)的函数,函数返回输入日期后面的那个日期。变量都具有整数值,且满足以下条件:
C1 1<=月份<=12
C2 1<=日期<=31
确定等价类
M1={月份:每月有30天}
M2={月份:每月有31天}
M3={月份:此月是2月}
D1={日期:1<=日期<=28}
D2={日期:日期=29}
D3={日期:日期=30}
D4={日期:日期=31}
Y1={年:年是闰年}
Y2={年:年是平年}
一般等价类测试用例应该有
3个(月份类)x 4个(日期类)x 2(年类)= 24个
24
25
26
2
2
2
27
28
30
2001
2001
2001
2001.2.28
2001.3.1
Day超出
2001.2.27
2001.2.28
Error input 通过分析前两个测试用例表,就会发现这些测试用例是不充分的,而且存在冗余。测试用例:
1.对日期进行测试
1)输入-1日,年月正常输入。
2)输入1日,年月正常输入。
3)输入15日,年月正常输入。
4)输入30日,年月正常输入。
5)输入30日,年月正常输入。
6)输入31日,年月正常输入。
7)输入32日,年月正常输入。
2.对月份进行测试
1)输入-1月,年正常输入。
2)输入1月,年日正常输入。
3)输入6月,年日正常输入。
4)输入12月,年日正常输入。
5)输入13月,年正常输入。
3.闰年的2月进行检测
4.检测平年的2月份
3.检测结果:
经过检测发现程序既能判断闰年,也能判断平年情况下的下一天的日期。计算的日期很准确
三、结论
1、实验结果
(1)在给定正常年月日的情况下,能够判断下一天的日期。
(2)输入的年月日不在正常范围,有提示,直到输入正确为止。
(3)既能判断平年,也能判断闰年的下一天日期。
2、分析讨论
本程序成功的实现了平年和闰年所输入日期的下一天的计算。
3、附加代码
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;
public class T {
public static int[] dates = new int[3];
public static void main(String[] args) throws Exception {
String[] input = { "input year :", "input month :", "input day :" };
Scanner sc = new Scanner(System.in);
for (int i = 0; i < input.length; i++) {
dates[i] = input(input[i], sc, i);
}
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, dates[0]);
calendar.set(Calendar.MONTH, dates[1] - 1);
calendar.set(Calendar.DATE, dates[2] + 1);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(sdf.format(calendar.getTime())); } public static int input(String message, Scanner sc, int index) { while (true) {
System.out.print(message);
String str = sc.nextLine();
try {
int result = Integer.parseInt(str);
if (index == 1 && !(result >= 1 && result <= 12)) {
System.out.println("月份必须在1≤month≤12之间");
continue;
}
if (index == 2) {
int end = endDay(dates[0], dates[1]);
if (!(result >= 1 && result <= end)) {
System.out.println("此年此月份的天数必须在1≤day≤" + end+"之间");
continue;
}
}
return result;
} catch (Exception e) {
System.out.println("input error!");
}
}
}
public static int endDay(int year, int month) {
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DATE, 0);
return c.get(Calendar.DATE);
} }
四、指导教师评语及成绩:
评语: