`

MyEclipse下JUnit的简单例子

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

  • 大小: 40.9 KB
  • 大小: 48.8 KB
  • 大小: 18.7 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics