实现步骤
-
- 一、创建服务接口
- 二、创建服务接口实现类
-
- 1.创建学校服务接口实现类
- 对CollegeServiceImpl进行单元测试
- 2.创建状态服务接口实现类
- 对StatusServiceImpl进行单元测试
- 3.创建学生服务接口实现类
- 对StudentServiceImpl进行单元测试
-
- 3.1 编写测试方testFindStudentsByName()
- 3.2 编写测试方法testAddStudent()
- 3.3 编写测试方法testDeleteStudentById()
- 3.4 编写测试方法testDeleteStudentsByClass()
- 3.5 编写测试方法testDeleteStudentsByDepartment()
- 3.6 编写测试方法testUpdateStudent()
- 3.7 编写测试方法testFindStudentById()
- 3.8 编写测试方法testFindAllStudents()
- 3.9 编写测试方法testFindStudentsByClass()
- 3.10 编写测试方法testFindStudentsByDepartment()
- 3.11 编写测试方法testFindRowsBySex()
- 3.12 编写测试方法testFindRowsByClass()
- 3.13 编写测试方法testFindRowsByDepartment()
- 4.创建用户服务接口实现类
- 对UserServiceImpl进行单元测试
- 总结
一、创建服务接口
1.创建学校服务接口
2.创建状态服务接口
3.创建学生服务接口
4.创建用户服务接口
二、创建服务接口实现类
1.创建学校服务接口实现类
package net.zhj.student.service.impl;
import net.zhj.student.bean.College;
import net.zhj.student.dao.CollegeDao;
import net.zhj.student.dao.impl.CollegeDaoImpl;
import net.zhj.student.service.CollgeService;
/**
* 功能:学校服务接口实现类
* 作者:朱虹菊
* 日期:2020年07月08日
*/
public class CollegeServiceImpl implements CollgeService {
private CollegeDao collegeDao = new CollegeDaoImpl();
@Override
public College findCollegeById(int id) {
return collegeDao.findById(id);
}
@Override
public int updateCollege(College college) {
return collegeDao.update(college);
}
}
对CollegeServiceImpl进行单元测试
1.1 编写测试方法testFindCollegeById()
package net.zhj.student.test;
import net.zhj.student.bean.College;
import net.zhj.student.service.CollgeService;
import net.zhj.student.service.impl.CollegeServiceImpl;
import org.junit.Test;
/**
* 功能:测试学校服务接口实现类
* 作者:朱虹菊
* 日期:2020年07月08日
*/
public class TestCollegeServiceImpl {
CollgeService service = new CollegeServiceImpl();
@Test
public void testFindCollegeById() {
College college = service.findCollegeById(1);
System.out.println("校名:" + college.getName());
System.out.println("校长:" + college.getPresident());
System.out.println("地址:" + college.getAddress());
System.out.println("邮箱:" + college.getEmail());
System.out.println("电话:" + college.getTelephone());
}
}
运行结果,如下:
1.2 编写测试方法testUpdateCollege()
@Test
public void testUpdateCollege() {
CollgeService service = new CollegeServiceImpl();
College college = service.findCollegeById(1);
college.setPresident("王洪礼");
college.setTelephone("0830-3150380");
int count = service.updateCollege(college);
if (count > 0) {
System.out.println("恭喜,学校记录更新成功!");
college = service.findCollegeById(1);
System.out.println(college);
} else {
System.out.println("遗憾,学校记录更新失败!");
}
}
运行结果,如下:
在Navicat中查看:
2.创建状态服务接口实现类
package net.zhj.student.service.impl;
import net.zhj.student.bean.Status;
import net.zhj.student.dao.StatusDao;
import net.zhj.student.dao.impl.StatusDaoImpl;
import net.zhj.student.service.StatusService;
/**
* 功能:状态服务接口实现类
* 作者:朱虹菊
* 日期:2020年07月08日
*/
public class StatusServiceImpl implements StatusService {
private StatusDao statusDao = new StatusDaoImpl();
@Override
public Status findStatusById(int id) {
return statusDao.findById(id);
}
@Override
public int updateStatus(Status status) {
return statusDao.update(status);
}
}
对StatusServiceImpl进行单元测试
2.1 编写测试方法testFindStatusById()
package net.zhj.student.test;
import net.zhj.student.bean.Status;
import net.zhj.student.service.StatusService;
import net.zhj.student.service.impl.StatusServiceImpl;
import org.junit.Test;
/**
* 功能:测试状态服务接口实现类
* 作者:朱虹菊
* 日期:2020年07月08日
*/
public class TestStatusServiceImpl {
StatusService service = new StatusServiceImpl();
@Test
public void testFindStatusById() {
Status status = service.findStatusById(1);
System.out.println("作者:" + status.getAuthor());
System.out.println("学校:" + status.getCollege());
System.out.