Web应用测试(bookstore项目上完成)

发表于:2016-6-14 10:55

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:不像样    来源:51Testing软件测试网采编

分享:
package org.easybooks.bookstore.action;
import org.easybooks.bookstore.service.IUserService;
import org.easybooks.bookstore.vo.User;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/*
* 用户注册(失败)
*  当密码或用户名为空时,则注册失败
*  Actor:王燕红
* */
public class UserActionTest {
@Test
public void testRegisterSuccess() throws Exception {
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
User user=new User();
user.setUsername("WYH");
user.setPassword("");
user.setSex("女");
user.setAge(23);
UserAction userAction=new UserAction();
userAction.setUser(user);
userAction.setUserService((IUserService)factory.getBean( "userService" ));
String result=userAction.register();
System.out.println("结果:"+user.getUsername()+"注册"+result);
}
}
  2、  编写单元测试用例,对用户注册功能的DAO层进行测试。(注意:测试用例应考虑成功和失败的情况)
  在TestUserDAO()中加入测试用例代码:
@Test
public void testUserReg(){
User user= new User();
user.setUsername("王燕红");
user.setSex("女");
user.setPassword("123456");
user.setAge(22);
try {
if(userDAO.exitUser(user.getUsername())){
System.out.println("注册失败,"+user.getUsername()+"用户名已经存在,请重新注册!!");
}else{
userDAO.saveUser(user);
System.out.println("注册用户:"+user.getUsername()+"成功");
}
} catch (Exception e) {
System.out.println("注册失败");
}
}
  若在重新运行一次则出现注册失败,提示重新注册!
22/2<12
2023测试行业从业人员调查问卷已开启,千元大奖正在等你~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2023
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号