Junit

1、Junit4去中央仓库搜索,依赖文件为: 

   <dependency>
	    <groupId>junit</groupId>
	    <artifactId>junit</artifactId>
	    <version>4.12</version>
	    <scope>test</scope>
	</dependency>

2、简单的helloworld

主文件DateUtil类在src/main/java文件中,需要一个返回值为boolean的函数,给定输入返回ture or false

测试文件JunitTest在src/test/java中,使用断言,给定输入值和期望的true或者false,Junit会检查每个测试点是否正确,

也可以使用maven build,则会把整个项目的所有测试文件一次性执行完。

package junitTest;

public class DateUtil {
	public boolean isLeapYear(int year) {
		if(year>0&&year<=10000) {
			if(year%100!=0&&year%4==0) {
				return true;
			}
			if(year%100==0&&year%400==0) {
				return true;
			}
		}
		return false;
	}
}
package junitTest;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class JunitTest {
		@Test
		public void test() {
			assertEquals(false,new DateUtil().isLeapYear(-100));
			assertEquals(false,new DateUtil().isLeapYear(1000));
			assertEquals(false,new DateUtil().isLeapYear(20000));
			assertEquals(true,new DateUtil().isLeapYear(2020));
			assertEquals(false,new DateUtil().isLeapYear(2019));
			assertEquals(true,new DateUtil().isLeapYear(2000));
			assertEquals(false,new DateUtil().isLeapYear(1900));
			
		}
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值