码迷,mamicode.com
首页 > Web开发 > 详细

实验七 Web应用测试_编写单元测试用例,对用户注册功能的DAO层进行测试

时间:2016-06-12 15:23:43      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

package testRegister;

import java.util.HashSet;

import junit.framework.Assert;

import org.easybooks.bookstore.dao.IUserDAO;

import org.easybooks.bookstore.vo.User;

import org.springframework.test.AbstractDependencyInjectionSpringContextTests;

 

public class TestUserDAO extends AbstractDependencyInjectionSpringContextTests{

//私有变量的Set方法来注入你想要的来自applicationContext中的bean,而不需要显式的调用applicationContext.getBean(XXX)

//该类会从getConfigLocations()方法指定的配置文件中帮你自动注入

private IUserDAO userDAO;

public void setUserDAO(IUserDAO _userDAO){

userDAO=_userDAO;

}

 

@Override

protected String[] getConfigLocations() {

//指定Spring配置文件applicationContext.xml

return new String[] {"classpath:org/easybooks/bookstore/test/applicationContext.xml"};

}

成功: 

/**

 * 测试UserDAO中的register()方法——注册成功

 */

public void testRegisterSuccess(){

User user = new User("wzw","wzw","man",22,new HashSet(0));

boolean isexit = userDAO.exitUser("wzw");

Assert.assertFalse(isexit);

userDAO.saveUser(user);

System.out.println("注册成功,用户为:"+user.getUsername());

}

 失败:

/**

 * 测试UserDAO中的register()方法——注册失败

 */

public void testRegisterFail(){

boolean isexit = userDAO.exitUser("ccj");

Assert.assertTrue(isexit);

System.out.println("注册失败");

}

}

实验七 Web应用测试_编写单元测试用例,对用户注册功能的DAO层进行测试

标签:

原文地址:http://www.cnblogs.com/3137102403qiulan/p/5577500.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!