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”
[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]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值