SSH框架学习(九、Junit4单元测试)

框架完成,开始一点一点添加其他内容。

myeclipse10自带有junit4,直接用就好,当然如果要下载也行。https://github.com/KentBeck/junit/downloads

在之前的基础上,我将dao和service层都改成了接口调用,其他没变。


对UserDAO进行测试,在myeclipse里面直接添加junit test case就好,然后再引入spring的test包:org.springframework.test-3.1.3.RELEASE

UserDAOImplTest代码如下

package demo.myssh.dao.impl;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.*;
import demo.myssh.dao.IUserDAO;
import demo.myssh.model.User;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"file:WebRoot/WEB-INF/applicationContext.xml"})
public class UserDAOImplTest {

	@Autowired
	@Qualifier("user")
	private User user;
	
	@Autowired
	@Qualifier("iUserDAO")
	private IUserDAO userDao;
	
	@Before
	public void setUp() throws Exception {
		user.setEmail("1email");
		user.setLoginName("1login name");
		user.setPassword("1assword");
	}
	
	@Test
	@Repeat(5)
	public final void testSave() {
		userDao.save(user);
		//fail("Not yet implemented"); 
	}
}

选择文件,run as -- junit test,

简单的测试,这样就算ok了。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值