等价类划分方法把所有可能的输入数据 (即程序的输入域) 划分成若干部分,然后从每一部分中选取少数有代表性的数据做 测试用例。使用等价类划分方法设计测试用例要经历划分等价类 (列出等价类表) 和确立测试用例两个步骤。
作业内容
构造 NextDate 问题的弱一般的等价类测试用例。
NextDate 问题:NextDate() 是整型变量 month, day 和 year 的函数,输入 1812-2012 年期间的某一日期的 month, day 和 year 的值,输出这一天的下一天的日期的 month, day 和 year 值。
内容说明
等价类的划分:
- 一个输入等价类是指程序输入域的某个子集,在该子集中,各个输入数据对于揭露程序中的错误是等效的。测试某一个等价类的代表值就等同于对这个等价类的其它值的测试。
- 等价类的划分有两种不同的情况:
- 有效等价类:对于程序规格说明来说是合理的、有意义的输入数据构成的集合。
- 无效等价类:对于程序规格说明来说是不合理的、无意义的输入数据构成的集合。
- 设计测试用例时,通常要求同时考虑有效等价类和无效等价类的用例设计。
- 这一类测试称为健壮性测试。
弱/强、一般/健壮的等价类测试分类:
- 弱 (weak) 等价类测试
- 针对单缺陷的等价类测试用例设计。
- 单缺陷:在同一输入条件下失效大概率由单个缺陷引起。
- 强 (strong) 等价类测试
- 针对多缺陷的等价类测试用例设计。
- 一般 (normal) 等价类测试
- 只覆盖有效等价类的测试用例设计。
- 健壮 (robust) 等价类测试
- 同时覆盖有效等价类和无效等价类的测试用例设计。
- 健壮性:软件在异常情况下还能正常运行的能力。健壮性 包括容错能力和异常恢复能力。容错性测试通常构造一些 不合理的输入来诱导软件出错。
解答
定义变量的取值范围如下:
- C1: 1 ≤ month ≤ 12
- C2: 1 ≤ day ≤ 31
- C3: 1812 ≤ year ≤ 2002
定义等价类如下:
- M1 = {month: month has 30 days}
- M2 = {month: month has 31 days except December}
- M3 = {month: month is December}
- M4 = {month: month is February}
- D1 = {day: 1 ≤ day ≤ 27}
- D2 = {day: day = 28}
- D3 = {day: day = 29}
- D4 = {day: day = 30}
- D5 = {day: day = 31}
- Y1 = {year: year is a leap year}
- Y2 = {year: year is a common year}
划分弱一般等价类如下:
- S1 = {M1, {D1, D2, D3}, {Y1, Y2}} Increment day
- S2 = {M1, D4, {Y1, Y2}} Reset day/Increment month
- S3 = {M2, {D1, D2, D3, D4}, {Y1, Y2}} Increment day
- S4 = {M2, D5, {Y1, Y2}} Reset day/Increment month
- S5 = {M3, {D1, D2, D3, D4}, {Y1, Y2}} Increment day
- S6 = {M3, D5, {Y1, Y2}} Reset day/Reset month/Increment year
- S7 = {M4, D1, {Y1, Y2}} Increment day
- S8 = {M4, D2, Y1} Increment day
- S9 = {M4, D2, Y2} Reset day/Increment month
- S10 = {M4, D3, Y1} Reset day/Increment month
- S11 = {others} Impossible
构造等价类的测试用例如下:
Test Case | Year | Month | Day | Expected Output | Expect |
---|---|---|---|---|---|
WN1 | 2001 | 4 | 20 | 2001/4/21 | Increment day |
WN2 | 2001 | 4 | 30 | 2001/5/1 | Reset day/Increment month |
WN3 | 2001 | 1 | 20 | 2001/1/21 | Increment day |
WN4 | 2001 | 1 | 31 | 2001/2/1 | Reset day/Increment month |
WN5 | 2001 | 12 | 20 | 2001/12/21 | Increment day |
WN6 | 2001 | 12 | 31 | 2002/1/1 | Reset day/Reset month/Increment year |
WN7 | 2001 | 2 | 20 | 2001/2/21 | Increment day |
WN8 | 2000 | 2 | 28 | 2000/2/29 | Increment day |
WN9 | 2001 | 2 | 28 | 2001/3/1 | Reset day/Increment month |
WN10 | 2000 | 2 | 29 | 2000/3/1 | Reset day/Increment month |
WN11 | 2001 | 4 | 31 | Error | Impossible |
WN11 | 2001 | 2 | 29 | Error | Impossible |
WN11 | 2000 | 2 | 30 | Error | Impossible |