目录
一、测试环境二、系统测试三、测试用例四、单元测试1、登录测试2、添加测试3、删除测试4、ID查找测试5、更新测试6、条件查找测试7、返回符合条件的用户数测试
一、测试环境
项目用户信息管理系统
操作系统WIN 10环境IDEA
二、系统测试
三、测试用例
四、单元测试
使用Junit 4进行测试
1、登录测试
@Test
public void login() {
UserDao userDao
=new UserDao();
User user
=new User();
user
.setUsername("guanyu");
user
.setPassword("1234");
if(userDao
.login(user
)==null
){
System
.out
.println("登录失败");
}else{
System
.out
.println("登陆成功");
}
}
输入可以匹配的用户名和密码,可以登陆成功,否则user为空,登录失败。
2、添加测试
@Test
public void add() {
UserDao userDao
=new UserDao();
User user
=new User();
user
.setName("刘亦菲");
user
.setUsername("liuyifei");
user
.setPassword("123");
user
.setGender("女");
user
.setAge(25);
user
.setAddress("北京");
user
.setQq("15466555");
user
.setEmail("1846554@qq.com");
userDao
.add(user
);
User user2
=new User();
user2
.setName("李易峰");
user2
.setUsername("liyifeng");
user2
.setPassword("123");
user2
.setGender("男");
user2
.setAge(28);
user2
.setAddress("西安");
user2
.setQq("1244665");
user2
.setEmail("111554@qq.com");
userDao
.add(user2
);
}
3、删除测试
@Test
public void delete() {
UserDao userDao
=new UserDao();
int num
=userDao
.delete(4);
System
.out
.println(num
);
int nums
=userDao
.delete(13);
System
.out
.println(num
);
}
根据传入的id删除,输入4,删除成功,输入13,因为该ID不存在,删除失败。
4、ID查找测试
@Test
public void find(){
UserDao userDao
=new UserDao();
User user
=userDao
.find(4);
System
.out
.println(user
);
User user2
=userDao
.find(14);
System
.out
.println(user2
);
}
输入4,id存在,查找成功,输入14,user2为空,查找失败。
5、更新测试
@Test
public void updateUser() {
User user
=new User();
UserDao userDao
=new UserDao();
user
.setId(11);
user
.setGender("男");
user
.setAge(32);
user
.setAddress("成都");
user
.setQq("123456");
user
.setEmail("123456@qq.com");
int ret
=userDao
.updateUser(user
);
if(ret
==0){
System
.out
.println("更新失败");
}else{
System
.out
.println("更新成功");
}
}
6、条件查找测试
@Test
public void findByPage() {
Map
<String
, String
[]> map
=new HashMap<>();
String
[] names
={""};
String
[] address
={"北京"};
String
[] emails
={""};
map
.put("name",names
);
map
.put("address",address
);
map
.put("emails",emails
);
UserDao userDao
=new UserDao();
List
<User> list
= userDao
.findByPage(0,5,map
);
for(User user
:list
){
System
.out
.println(user
);
}
}
输入条件为地址北京,查找出结果。三个条件都为空,则打印全部。
7、返回符合条件的用户数测试
@Test
public void findAllRecord() {
Map
<String
, String
[]> map
=new HashMap<>();
UserDao userDao
=new UserDao();
String
[] names
={""};
String
[] address
={""};
String
[] emails
={""};
map
.put("name",names
);
map
.put("address",address
);
map
.put("emails",emails
);
int size
=userDao
.findAllRecord(map
);
System
.out
.println("记录一共有 "+size
+"条。");
}