我在我的组织中有一个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;
}
}
CaseComment
是一个与Case
相关联的对象,所以你所要做的就是改变你的触发器类,使其在Case对象中使用,而不是CaseComment
对象。
你的触发器应该是这样的:
trigger CaseTrigger on Case (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;
Test.StartTest();
CaseComment tComment = new CaseComment();
tComment.ParentId = tCase.Id;
tComment.CommentBody = 'Some Comment';
tComment.IsPublished = TRUE;
INSERT tComment;
Test.StopTest();
}
}