0

TimelineCase クラスでは、ここで recordId と pageNo とページ サイズを processTimelineItem() メソッドで送信しています。このクラスで sql を使用してケース レコードをフェッチすることを期待しています。しかし、ここでは SQL ケース レコードをカバーでき、ケース レコードをフェッチできません。

私は自分の知識でいくつかのテスト クラスを作成しました。100% の apex コード カバレッジを達成できましたが、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