参考文档:转载他人的
http://dongbiying.iteye.com/blog/1002188
http://tonl.iteye.com/blog/1948869
http://blog.csdn.net/shuangde800/article/details/9109081
===========================================================
![](https://img-blog.csdn.net/20161117124850097?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
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");
}
}
其他代码没变!!!!!!!!!!!!!!!!!!!!!!!
===============================================================