/*
* JUit的简介的使用的步骤:
* 1.使用@Test标注,表示这个一个测试的方法,相当于是一个main方法
* 2.方法的名称可以随便取,但是要注意规范,类似 test+方法名称
* 3.方法返回值一定是void的
* 4.方法不能有任何的参数
* 5.可以抛出异处理的
* 6.我们做的抛出异常是不可取的,Juint使用自带的异常处理类Assert(断言类)
*/
@Test
public void testAdd1() throws Exception{
MathUtil mu = new MathUtil();
int a = 10;
int b =5;
int result = mu.add(a,b);
if (result!=15){
throw new RuntimeException("运行错误了");
}
}
3.JUnit的抛出异常 (Assert断言类)
@Test
public void testAdd(){
MathUtil mu = new MathUtil();
int a = 10 ;
int b = 20 ;
int result = mu.add(a,b);
//是否相等的操作,第一个参数为期待的值,后面为实际的值
//Assert.assertEquals(30,result);
//不相等,第一个参数为不期待的值,后面是期待的值
Assert.assertNotEquals(20,result);
}