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

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

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

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

  1、  编写单元测试用例,对用户注册功能的Action层进行测试。(注意:测试用例应考虑成功和失败的情况)
  先在原来的UserAction类加入判断代码当用户名或密码为空时则注册失败:
public String register() throws Exception{
if("" == user.getUsername()||""==user.getPassword()){
return "error";
}
else{
userService.saveUser(user);
return SUCCESS;
}
}
  然后在UserAction类上创建一个测试类:
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("123456");
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);
}
}
  当用户和密码不为空时,则用户注册成功:
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

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

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

沪ICP备05003035号

沪公网安备 31010102002173号