1.下载Junit
2.Eclipse创建项目Junit001,创建lib文件夹,把下载的junit的jar包放在lib文件夹下,并buildpath进去,创建class文件Calcuate.java内容如下:
package com.leung;
public class Calcuate {
public int add(int a,int b){ return a+b; }}3.创建Junit Test Case:testCalcuate.java,内容如下:
package com.leung;
import static org.junit.Assert.fail;
import org.junit.Assert;
import org.junit.Before;import org.junit.Test;import com.leung.Calcuate;
public class testCalcuate {
Calcuate cal;@Before
public void setUp() throws Exception { cal = new Calcuate(); }@Test
public void test() { int rel = cal.add(10, 12); Assert.assertEquals("加法有问题", rel, 22); }}然后运行:run as -Junit Test
出现
参考:http://huihai.iteye.com/blog/1986568