0

我在我的组织中有一个 CaseComment 对象的触发器,其中只有一行代码来调用另一个顶点类的静态方法。但是触发器的覆盖率为 0%。我编写了一个测试类来获得覆盖率,但它根本不起作用。谁能告诉我为什么它没有覆盖触发器以及如何覆盖它?提前致谢。

触发代码是

trigger CaseCommentTrigger on CaseComment (after Insert) {
    CaseCommentTriggerUtil.notifyCaseRequestorAndCreator(Trigger.New);
}

我的测试课是

@isTest
public with sharing class CaseCommentTriggerTest {
    @isTest
    public static void createCaseComment() {
        Case tCase = new Case();

        tCase.Status = 'New';
        tCase.Description = 'Test Description';
        tCase.Origin = 'Email';
        tCase.Priority = 'Low';
      
        INSERT tCase;
        
        CaseComment tComment = new CaseComment();
        tComment.ParentId = tCase.Id;
        tComment.CommentBody = 'Some Comment';
        tComment.IsPublished = TRUE;
        
        INSERT tComment;
    
    }
}
4

2 回答 2

0
@isTest
public with sharing class CaseCommentTriggerTest {
    @isTest
    public static void createCaseComment() {
        Case tCase = new Case();

        tCase.Status = 'New';
        tCase.Description = 'Test Description';
        tCase.Origin = 'Email';
        tCase.Priority = 'Low';
      
        INSERT tCase;
        
        Test.StartTest();
        CaseComment tComment = new CaseComment();
        tComment.ParentId = tCase.Id;
        tComment.CommentBody = 'Some Comment';
        tComment.IsPublished = TRUE;
        
        INSERT tComment;
        Test.StopTest();
    }
}
于 2021-11-14T18:43:44.810 回答
0

CaseComment是一个与 a 关联的对象Case,因此您所要做的就是更改要在 Case 对象中使用的触发器类,而不是CaseComment对象。

你的触发器应该是这样的:

trigger CaseTrigger on Case (after insert) {

   CaseCommentTriggerUtil.notifyCaseRequestorAndCreator(Trigger.New);
   
}
于 2021-10-14T08:11:38.433 回答