java - Writing unit test for service function -


I need some help to write tests for the method below in the service layer. I'm not sure that in Mokito How to duplicate these services (such as the same service layer as DAO) for this service before I think that I should be completely duplicate the loop to avoid the mockery of all those methods. What is the proper way to write unit exams for such a method.

  Public list & amp; Lt; CheckupHindiData & gt; GetCaseHistory (Personalized Patient, Personal Doctor) {List & amp; check; Checkup History DTO & gt; Checkuplistslist = new arreelist & amp; Claims history & gt; (); & Lt; CaseHistory & gt; CaseHistoryIds = caseDetailDao.fetchCaseIds (Patient.GetID), Doctor .getId ()); (CaseHistory case history: caseHistoryIds) {Checkup history check upHindida = new checkHindi (); CheckupHistoryDto.setDateOfCall (formatter.format (caseHistory.getCreateDate ())); CheckupHistoryDto.setPatientInfo (getPatientInfo (Patient)); CheckupHistoryDto.setDoctorInfo (getDoctorInfo (Doctor)); CheckupHistoryDto.setServiceProvided (caseDetailDao.fetchServiceHistory (caseHistory.getEventId ())); CheckupHistoryList.add (checkupHistoryDto); } Returns checklist of theist list; } Public patient getPatientInfo (Patient) {...} Public Doctor getDoctorInfo (Doctor) {...}  

and my trial cases

  @ Test Public Zero Test History List () {Personal Patient = Mokito. Mock (individual square); Individual Doctor = Mokito Mock (personal class); & Lt; CheckupHistoryDto & gt; CheckupHistory = caseService.getCaseHistory (Patient, Doctor); Emphasizing values ​​(MOCK_LIST_SIZE, checkup history. Size ()); } "Forget about" the fun of for loop ", it does not mean anything Not because this is part of the functionality that you want to test; Specifically, when you use Unit Test Class XQ, you never mimic any part of class XQ.  

There is a need to follow:

  1. individual.getId for the patient.
  2. Individual.getId for the doctor.
  3. For the patient GetPatientInfo used by the method Methods of individual classes to be performed.
  4. Methods to use on individual class methods by the getDoctorInfo method for the doctor.
  5. caseDetailDao.fetchCaseIDs
  6. caseDetailDao.fetchServiceHistory
  7. caseHistory.getCreateDate, if you return a list of duplicate items from fetchCaseIds.
  8. caseHistory.getEventId, if you duplicate from fetchCaseIds Returns a list of items.

You have some terrible codes:

  1. caseHsitory.fetchCaseIds obviously case ID Returning the same time, it is returned to the case details.

Comments