参考文档:转载他人的
http://dongbiying.iteye.com/blog/1002188
http://tonl.iteye.com/blog/1948869
http://blog.youkuaiyun.com/shuangde800/article/details/9109081
===========================================================

package com.fjnu.util;
public class Calculate {
public int add(int a, int b){
return a+b;
}
}
--------------------------------------
package com.fjnu.test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import com.fjnu.util.Calculate;
public class test1 {
//@Before
//public void setUp() throws Exception {
//}
@Test
public void testAdd() {
int z = new Calculate().add(2, 3);
//assertEquals(z,5);
assertEquals("加法有问题", 5, z);
//fail("Not yet implemented");
}
}
===============================================
案例改进:
package com.fjnu.test;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import com.fjnu.util.Calculate;
public class test1 {
Calculate cal;
@Before
public void setUp() throws Exception {
cal = new Calculate() ;
}
@Test
public void testAdd() {
assertEquals("加法有问题", 5, cal.add(2, 3));
// fail("Not yet implemented");
}
}
其他代码没变!!!!!!!!!!!!!!!!!!!!!!!
===============================================================