在MyEclipse下使用Junit,以一个最简单的例子来记录整个过程
一、创建一个待测试类JunitDemo
二、鼠标右击待测试类,加入“JUnit Test Case”
[img]http://dl.iteye.com/upload/attachment/263628/ae90736a-464a-341b-b5b0-d2abb009bf4a.jpg[/img]
新建测试类TestJunitDemo
[img]http://dl.iteye.com/upload/attachment/263630/7994b660-0d0b-3de0-9df5-87243f90a240.jpg[/img]
三、写测试类实现代码
四、运行Run As ->JUnit Test,
在JUnit测试平台中,绿色表示测试通过,红色表示未通过,如下图:
[img]http://dl.iteye.com/upload/attachment/263635/1bf08a13-1528-3d65-a8fa-0c6ba9b8acdf.jpg[/img]
一、创建一个待测试类JunitDemo
/*
* 测试使用Junit
*/
public class JunitDemo {
public static void main(String[] args) {
}
public String returnstring(){
return "I'm good";
}
}
二、鼠标右击待测试类,加入“JUnit Test Case”
[img]http://dl.iteye.com/upload/attachment/263628/ae90736a-464a-341b-b5b0-d2abb009bf4a.jpg[/img]
新建测试类TestJunitDemo
[img]http://dl.iteye.com/upload/attachment/263630/7994b660-0d0b-3de0-9df5-87243f90a240.jpg[/img]
三、写测试类实现代码
import junit.framework.TestCase;
public class TestJunitDemo extends TestCase {
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void testReturnstring() {
JunitDemo jd = new JunitDemo();
this.assertEquals("I'm good", jd.returnstring());
}
}
四、运行Run As ->JUnit Test,
在JUnit测试平台中,绿色表示测试通过,红色表示未通过,如下图:
[img]http://dl.iteye.com/upload/attachment/263635/1bf08a13-1528-3d65-a8fa-0c6ba9b8acdf.jpg[/img]