在TimelineCase类中,在这里我们在processTimelineItem()方法中发送了recordId和pageNo以及pase的大小,期望在此类中使用sql来获取案例记录。但是这里我们可以覆盖sql案例记录,而无法获取案例记录。
据我所知,我编写了一些测试类,能够达到100%的顶点代码覆盖率,但由于System.assertEquals(applicantId,testFilteredObjects [0] .actor),我的测试类仍然失败。接下来,请尝试理解我的测试类,或者使用它,请通过理解来编写新的测试类。提前非常感谢!
我写了一些测试课程,我可以在课程中100%覆盖代码,但是我的测试课程仍然失败。
TimelineCase class
public class TimelineCase extends TimelineObject implements TimelineObject{
public List<TimelineObject> processTimelineItem(id recordId, Integer pageNo, Integer pageSize){
List<TimelineObject> wrappedCase = new List<TimelineObject>();
List<Case> t = [SELECT Id, Subject, AccountId, CreatedDate, CreatedBy.Name
FROM Case
WHERE Applicant__c = :recordId
LIMIT :pageSize
OFFSET :pageNo];
if(t != null){
for(Integer i = 0, CaseSize = t.size(); i < CaseSize; i++){
wrappedCase.add(new TimelineObject().setActor(t[i].CreatedBy.Name)
.setHeader(t[i].Subject)
.setDate(t[i].CreatedDate.format())
.setIconName('standard:case')
.setIconColour('put the colour in here'));
}
}
return wrappedCase;
}
}
I have tried some test class for your reference,
Test class for TimelineCase
@isTest
public class TimelineCaseTest {
@isTest
public static void itShouldBeAbleToGetApplicantCaseListTest1(){
String applicantId = new TimelineControllerBuilder().save();
Case caseApplicant = new CaseBuilder().withApplicant(applicantId)
.save();
TimelineCase TimelineCase = new TimelineCase();
Test.startTest();
List<TimelineObject> testFilteredObjects = TimelineCase.processTimelineItem(applicantId, 1, 10);
Test.stopTest();
System.debug('Case result' + caseApplicant.CreatedBy.Name + testFilteredObjects[0].actor);
System.assertEquals(1, testFilteredObjects.size());
// applicantId returns case record
System.assertEquals(applicantId, testFilteredObjects[0].actor);
// applicantId returns current created date and time of case record
System.assertEquals((applicantId, , testFilteredObjects[0].itemDate);
System.assertEquals('standard:case', testFilteredObjects[0].iconName);
System.assertEquals('put the colour in here', testFilteredObjects[0].iconColour);
}
}
Please let me know if you need further information
// returning the user name who is creating the case record
System.assertEquals(applicantId, testFilteredObjects[0].actor);
//// returning the created date and time who is creating the case record
System.assertEquals(applicantId, testFilteredObjects[0].itemDate);
}