幕测平台 您所在的位置:网站首页 mooctest参数化得分为0 幕测平台

幕测平台

2024-07-05 22:59| 来源: 网络整理| 查看: 265

需求

NextDay是一个简单的日期计算器,计算给定日期的下一天的具体日期。如给定2020年1月1日,返回2020年1月2日;给定2020年1月31日,返回2020年2月1日。主要要求考察学生对日期边界以及异常处理的测试的能力。

实现

NextdayTest.java

package net.test; import static org.junit.Assert.*; import static org.junit.matchers.JUnitMatchers.containsString; import net.mooctest.*; import org.junit.Assert; import org.junit.Test; import org.junit.rules.ExpectedException; public class NextdayTest02 { // 有效 @Test public void testDate01() { Date date = new Date(2,29,2016); Date d = Nextday.nextDay(date); String result = d.toString(); Assert.assertEquals("3/1/2016",result); } @Test public void testDate02() { Date date = new Date(2,28,2017); Nextday n = new Nextday(); Date d = Nextday.nextDay(date); String result = d.toString(); Assert.assertEquals("3/1/2017",result); } @Test public void testDate03() { Date date = new Date(1,31,2017); Nextday n = new Nextday(); Date d = Nextday.nextDay(date); String result = d.toString(); Assert.assertEquals("2/1/2017",result); } @Test public void testDate04() { Date date = new Date(4,30,2017); Nextday n = new Nextday(); Date d = Nextday.nextDay(date); String result = d.toString(); Assert.assertEquals("5/1/2017",result); } @Test public void testDate05(){ try{ Date date = new Date(-1,1,1901); Nextday n = new Nextday(); Date d = Nextday.nextDay(date); }catch (IllegalArgumentException e){ assertThat(e.getMessage(), containsString("Not a valid month")); } } @Test public void testDate06(){ try{ Date date = new Date(13,1,1901); Nextday n = new Nextday(); Date d = Nextday.nextDay(date); }catch (IllegalArgumentException e){ assertThat(e.getMessage(), containsString("Not a valid month")); } } @Test public void testDate07(){ try{ Date date = new Date(1,-1,1901); Nextday n = new Nextday(); Date d = Nextday.nextDay(date); }catch (Illega


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有