0

在 TimelineCase 类中,这里我们在 processTimelineItem() 方法中发送 recordId 和 pageNo 以及 pase 大小,期望它会在该类中使用 sql 获取案例记录。但是这里我们可以覆盖sql case记录,无法获取case记录。

据我所知,我编写了一些测试类,我能够实现 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);

}

4

0 回答 0