小结
继续完成上午没有写完的测试类和用户接口。
创建学生服务测试类
独立完成剩余方法的测试任务
(1)编写测试方法testAddStudent()
@Test
public void testAddStudent() {
//创建学生对象
Student student = new Student();
//设置学生对象属性
student.setId("19205213");
student.setName("林秒秒");
student.setSex("女");
student.setAge(20);
student.setDepartment("艺术传媒学院");
student.setClazz("18数媒4班");
student.setTelephone("13890673428");
//调用学生数据访问对象的插入方法,
int count = service.addStudent(student);
//判断学生记录是否插入成功
if (count > 0) {
System.out.println("恭喜,学生记录插入成功!");
System.out.println(service.findStudentById(student.getId()));
} else {
System.out.println("遗憾,学生记录插入失败!");
}
}
(2)编写测试方法testDeleteStudentById()
@Test
public void testDeleteStudentById() {
String id = "18205226";
//调用学生数据访问对象的按id删除方法,
int count = service.deleteStudentById(id);
//判断学生记录是否删除成功
if (count > 0) {
System.out.println("恭喜,学生记录删除成功!");
} else {
System.out.println("遗憾,学生记录删除失败!");
}
}
(3)编写测试方法testDeleteStudentsByClass()
@Test
public void testDeleteStudentsByClass() {
String clazz = "18小教3班";
//调用学生数据访问对象的按班级删除方法,
int count = service.deleteStudentsByClass(clazz);
//判断学生记录是否删除成功
if (count > 0) {
System.out.println("恭喜,[" + clazz + "]学生记录删除成功!");
} else {
System.out.println("遗憾,[" + clazz + "]学生记录删除失败!");
}
}
(4)编写测试方法testDeleteStudentsByDepartment()
@Test
public void testDeleteStudentsByDepartment() {
String department = "商学院";
//调用学生数据访问对象的按学院删除方法,
int count = service.deleteStudentsByDepartment(department);
//判断学生记录是否删除成功
if (count > 0) {
System.out.println("恭喜,[" + department + "]学生记录删除成功!");
} else {
System.out.println("遗憾,[" + department + "]学生记录删除失败!");
}
}
(5)编写测试方法testUpdateStudent()
@Test
public void testUpdateStudent() {
//调用学生数据访问对象的查询方法
Student student = service.findStudentById("18205224");
//修改学生属性
student.setName("程晓心");
student