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了。