封装类
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/
这是我第一次做测试单元,存在很多不足,我以后会慢慢改进的。
因为五一要去远方,加上请假两天,所以作业有点赶,望老师和队友见谅。