ITeye博客

MyEclipse下JUnit的简单例子

GreatNeyo · 2010-06-12 11:09 · 软件测试 · 编程语言 · junit · Myeclipse · Markdown

在MyEclipse下使用Junit,以一个最简单的例子来记录整个过程 一、创建一个待测试类JunitDemo


/*
 * 测试使用Junit
 */
public class JunitDemo {
	public static void main(String[] args) {	
	}
	public String returnstring(){
		return "I'm good";
	}
}


二、鼠标右击待测试类,加入“JUnit Test Case” 新建测试类TestJunitDemo 三、写测试类实现代码


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测试平台中,绿色表示测试通过,红色表示未通过,如下图:

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。