http://blog.csdn.net/wuyt2008/article/details/8275096
框架完成,开始一点一点添加其他内容。
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了。