0
我需要一些幫助來爲服務層中的以下方法編寫測試。我不確定如何在Mockito中爲這項服務模擬這些方法(在DAO以及相同的服務層中)。在此之前,我認爲我應該嘲笑整個循環,以避免嘲笑每種方法。爲這種方法編寫單元測試的正確方法是什麼?編寫服務功能的單元測試
public List<CheckupHistoryDto> getCaseHistory(Individual patient, Individual doctor) {
List<CheckupHistoryDto> checkupHistoryList = new ArrayList<ClaimHistoryDto>();
List<CaseHistory> caseHistoryIds = caseDetailDao.fetchCaseIds(patient.getId(), doctor.getId());
for(CaseHistory caseHistory : caseHistoryIds) {
CheckupHistoryDto checkupHistoryDto = new CheckupHistoryDto();
checkupHistoryDto.setDateOfCall(formatter.format(caseHistory.getCreateDate()));
checkupHistoryDto.setPatientInfo(getPatientInfo(patient));
checkupHistoryDto.setDoctorInfo(getDoctorInfo(doctor));
checkupHistoryDto.setServiceProvided(caseDetailDao.fetchServiceHistory(caseHistory.getEventId()));
checkupHistoryList.add(checkupHistoryDto);
}
return checkupHistoryList;
}
public Patient getPatientInfo(patient) {
...
}
public Doctor getDoctorInfo(doctor) {
...
}
我的測試用例
@Test
public void testHistoryList() {
Individual patient = Mockito.mock(Individual.class);
Individual doctor= Mockito.mock(Individual.class);
List<CheckupHistoryDto> checkupHistory = caseService.getCaseHistory(patient, doctor);
assertEquals(MOCK_LIST_SIZE, checkupHistory.size());
}