封裝類
package com.szys.junit;
public class Packaging {
int m;
int n;
public T(int m,int n)
{
this.m=m;
this.n=n;
}
public int add()
{
return m + n;
}
public int minus()
{
return m - n;
}
public int mul()
{
return m * n;
}
public int div()throws Exception
{
if(0 == n)
{
throw new Exception("除數不能為0");
}
return m / n;
}
}
測試類
package com.szys.junit.test;
import static org.junit.Assert.*;
import org.junit.Test;
import com.szys.junit.T;
public class Test {
public void test() {
int m=new T(1, 2).add();
assertEquals(3, m);
int n=new T(4, 3).minus();
assertEquals(1,n);
int x=new T(3, 4).mul();
assertEquals(12,x);
try {
int y=new T(4, 4).div();
assertEquals(1, y);
}catch(Exception e){
e.printStackTrace();
}
}
}
結伴隊友:黃傑:http://www.cnblogs.com/hj1994/
這是我第一次做測試單元,存在很多不足,我以後會慢慢改進的。
因為五一要去遠方,加上請假兩天,是以作業有點趕,望老師和隊友見諒。