次日问题测试实验报告

软件测试实验报告

课程名称

软件质量保证与测试

班级

实验日期

姓名

学号

实验地点

实验名称

次日问题

实验目的与要求

1、掌握应用黑盒测试技术进行测试用例设计。

2、掌握对测试用例进行优化设计方法。

实验环境

Idea、亿图图示

实验内容

程序有三个输入变量month、day、year(month、day和year均为整数值,并且满足:1≤month≤12、1≤day≤31和1900≤year≤2050),分别作为输入日期的月份、日、年份,通过程序可以输出该输入日期在日历上隔一天的日期。例如,输入为2020年11月30日,则该程序的输出为2020年12月1日。

一、问题分析与设计

 

 

二、编写实验代码

实验类代码:

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class ciri {

    public static void main(String[] args) throws IOException {

        int year, month, day;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        System.out.println("输入年:");

        year = Integer.parseInt(br.readLine());

        System.out.println("输入月:");

        month = Integer.parseInt(br.readLine());

        System.out.println("输入日:");

        day = Integer.parseInt(br.readLine());

        String nextday = ciri.nextDate(year, month, day);

        System.out.println("下一天为" + nextday);

    }

    public static String nextDate(int y, int m, int d) {

        int year, month, day;

        year = y;

        month = m;

        day = d;

        String result = new String();

        switch (month) {

            case 1:

            case 3:

            case 5:

            case 7:

            case 8:

            case 10:

                if (day == 31) {

                    day = 1;

                    month = month + 1;

                } else

                    day = day + 1;

                break;

            case 4:

            case 6:

            case 9:

            case 11:

                if (day == 30) {

                    day = 1;

                    month = month + 1;

                } else if (day == 31) {

                    System.out.println("无效输入日期!");

                } else

                    day = day + 1;

                break;

            case 12:

                if (day == 31) {

                    day = 1;

                    month = 1;

                    year = year + 1;

                } else if (day < 31) {

                    day = day + 1;

                }

                break;

            case 2: {

                if (day == 28)

                    if (((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)) {

                        day = 29;

                    } else {

                        day = 1;

                        month = 3;

                    }

                else if (day == 29) {

                    day = 1;

                    month = 3;

                } else if (day < 28) {

                    day = day + 1;

                } else {

                    result = "无效输入日期!";

                }

            }

            break;

            default:

        }

        if (year >= 1900 && year <= 2050 && month <= 12 && month >= 1

                && day <= 31 && day >= 1) {

            StringBuilder months = new StringBuilder();

            StringBuilder days = new StringBuilder();

            if (month < 10)

                months = months.append(0).append(month);

            else

                months = months.append(month);

            if (day < 10)

                days = days.append(0).append(day);

            else

                days = days.append(day);

            StringBuilder resultB = new StringBuilder().append(year).append(months).append(days);

            result = resultB.toString();

        } else if (year < 1900 || year > 2050) {

            result = "年的值不在指定范围内";

        } else if (month > 12 || month < 1) {

            result = "月的值不在指定范围内";

        } else if (day > 31 || day < 1) {

            result = "日的值不在指定范围内";

        } else result = null;

        return result;

    }

}

测试类代码:

import org.junit.Assert;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.junit.runners.Parameterized;

import java.util.Arrays;

import java.util.Collection;

@RunWith(Parameterized.class)

public class ceshi {

    private int input1;

    private int input2;

    private int input3;

    private String expected;

    @Parameterized.Parameters

    public static Collection<?> prepareData(){

        Object [][] object = {

                //年

                {1889, 7, 10, "年的值不在指定范围内"},

                {1900, 7, 10, "19000711"},

                {1901, 7, 10, "19010711"},

                {2049, 7, 10, "20490711"},

                {2050, 7, 10, "20500711"},

                {2051, 7, 10, "年的值不在指定范围内"},

                //月

                {2019, 0, 10, "月的值不在指定范围内"},

                {2019, 1, 10, "20190111"},

                {2019, 2, 10, "20190211"},

                {2019, 11, 10, "20191111"},

                {2019, 12, 10, "20191211"},

                {2019, 13, 10, "月的值不在指定范围内"},

                //日

                {2019, 2, 27, "20190228"},

                {2019, 2, 28, "20190301"},

                {2019, 2, 29, "日的值不在指定范围内"},

                {2020, 2, 28, "20200229"},

                {2020, 2, 29, "20200301"},

                {2020, 2, 30, "日的值不在指定范围内"},

                {2019, 1, 30, "20190131"},

                {2019, 1, 31, "20190201"},

                {2019, 1, 32, "日的值不在指定范围内"},

                {2019, 4, 30, "20190501"},

                {2019, 4, 31, "日的值不在指定范围内"},

                {2019, 4, 32, "日的值不在指定范围内"},

        };

        return Arrays.asList(object);

    }

    public ceshi(int input1,int input2,int input3,String expected){

        this.input1 = input1;

        this.input2 = input2;

        this.input3 = input3;

        this.expected = expected;

    }

    @Test

    public void testDate(){

        String result = ciri.nextDate(input1,input2,input3);

        Assert.assertEquals(expected, result);

    }

}

三、编写测试用例

序号

期望输出

1

1889

7

10

年的值不在指定范围内

2

1900

7

10

19000711

3

1901

7

10

19010711

4

2049

7

10

20490711

5

2050

7

10

20500711

6

2051

7

10

年的值不在指定范围内

7

2019

7

10

月的值不在指定范围内

8

2019

0

10

20190111

9

2019

1

10

20190211

10

2019

2

10

20191111

11

2019

11

10

20191211

12

2019

12

10

月的值不在指定范围内

13

2019

13

27

20190228

14

2019

2

28

20190301

15

2019

2

29

日的值不在指定范围内

16

2020

2

28

20200229

17

2020

2

29

20200301

18

2020

2

30

日的值不在指定范围内

19

2019

1

30

20190131

20

2019

1

31

20190201

21

2019

1

32

日的值不在指定范围内

22

2019

4

30

20190501

23

2019

4

31

日的值不在指定范围内

24

2019

4

32

日的值不在指定范围内

测试结果:

 

通过本次实验,掌握了应用黑盒测试技术进行测试用例设计,掌握了对测试用例进行优化设计方法,能用Junit实施参数化测试。

  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

.wei-upup

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值