Junit简单复习

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import MyMath;
//测试方法:带有@Test注解。方法是public的,没有返回值和参数的
public class MyMathTest {
	private static MyMath mm;
	
	@BeforeClass
	public static void bb(){
		mm = new MyMath();
//		System.out.println("bb");
	}
	@AfterClass
	public static void aa(){
		mm = null;
//		System.out.println("aa");
	}
	
//	@Before//每个测试方法开始前执行
//	public void b1(){
//		mm = new MyMath();
//		System.out.println("before");
//	}
//	@After
//	public void a1(){
//		mm = null;
//		System.out.println("after");
//	}
	
	
	@Test
	public void testAdd() {
//		MyMath mm = new MyMath();
		int result = mm.add(1, 2);
		assertEquals(3, result);
	}

	@Test
	public void testDivide() {
//		MyMath mm = new MyMath();
		int result = mm.divide(10, 2);
		assertEquals(5, result);
	}
	
	//测试出现的异常
	@Test(expected=java.lang.ArithmeticException.class)
	public void testDivide1() {
//		MyMath mm = new MyMath();
		mm.divide(10, 0);
	}
	//测试执行效率:运行时间不能超过1秒钟
	@Test(timeout=1000)
	public void testDivide2(){
//		MyMath mm = new MyMath();
		int result = mm.divide(10, 2);
		assertEquals(5, result);
	}
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值