0

我是销售人员开发的新手。我已经为以下触发器编写了测试类,它的覆盖范围仅为 53。我通过在测试类中添加和更改代码行尝试了几次,但它仍然显示 53。你能帮我解决这个问题吗?

提前致谢。任何帮助,将不胜感激。

        trigger CaseTrigger on Case (before insert,before update, after update) 
{
    if((Trigger.isBefore && Trigger.isUpdate)||(Trigger.isBefore && Trigger.isInsert))
    {

   List<Id> contactIds = new List<Id>();
   List<Id> acctIds = new List<Id>();
   for (Case c: Trigger.new){
      if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){
         contactIds.add(c.ContactId);
         acctIds.add(c.AccountId);
      }
   }
   if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){
      /* Added check for active entitlement */
      List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e
                                                Where e.ContactId in:contactIds
                                                And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today];
      if(entlContacts.isEmpty()==false){
         for(Case c: Trigger.new){
            if(c.EntitlementId == null && c.ContactId!= null){
               for(EntitlementContact ec:entlContacts){
                  if(ec.ContactId==c.ContactId){
                     c.EntitlementId = ec.EntitlementId;
                     if(c.AssetId==null && ec.Entitlement.AssetId!=null)
                        c.AssetId=ec.Entitlement.AssetId;
                     break;
                  }
               } // end for entitlement
            }
         } // end for case
      } else{
         List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
                                     From Entitlement e
                                     Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today];
         if(entls.isEmpty()==false){
            for(Case c: Trigger.new){
               if(c.EntitlementId == null && c.AccountId!= null){
                  for(Entitlement e:entls){
                     if(e.AccountId==c.AccountId){
                        c.EntitlementId = e.Id;
                        if(c.AssetId==null && e.AssetId!=null)
                           c.AssetId=e.AssetId;
                        break;
                     }
                  } // end for
               }
            } // end for
         }
      }
   } // end if(contactIds.isEmpty()==false)

    }


    if(Trigger.isBefore && Trigger.isUpdate)
    {
        System.debug('entered if condition');

        for(Case c : Trigger.new)
        {
            if (c.Assignment_Group__c != trigger.oldMap.get(c.Id).Assignment_Group__c){
            System.debug('Updating logic');
            List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue'];
              for(Group g : qid)
                {
                    c.OwnerId = g.id;
                    System.debug('updated');
                }
            }}        
    }

     if(Trigger.isBefore && Trigger.isUpdate)
    {
      for(Case c : Trigger.new)
        {   
            if(c.Assignment_Group__c=='Tech Support'||c.Assignment_Group__c=='GD-IT'||c.Assignment_Group__c=='App-Support'||c.Assignment_Group__c=='GD-RM'||c.Assignment_Group__c=='GD-DB'||c.Assignment_Group__c=='Dev-Ops'||c.Assignment_Group__c=='App-Management'||c.Assignment_Group__c=='PDT-DS-Engg'||c.Assignment_Group__c=='PDT-US-Engg')
            {
                c.Group_Manager_Email__c = 'sargware@gmail.com'; c.Escalation_Level_2_Email__c ='sargware@gmail.com'; c.Escalation_Level_3_Email__c='sargware@gmail.com';
            }
        }
    }

    if(Trigger.isBefore && Trigger.isUpdate)
    {
      for(Case c : Trigger.new)
        {   
            if(c.Internal_Impact__c == 'Low' && c.Internal_Urgency__c=='Low')
            {
                c.Priority='Planning';
            }
            if(c.Internal_Impact__c == 'High' && c.Internal_Urgency__c=='High')
            {
                c.Priority='Critical';
            }
            if(c.Status=='Pending User' || c.Status=='Pending Vendor')
            {
                c.IsStopped = True;
            }

        }

      }

    if((Trigger.isAfter && Trigger.isUpdate))
    {
    Set<Id> Ids = new Set<Id>();
    Set<Id> IdR = new Set<Id>();
    Set<Id> IdC = new Set<Id>();
    List<SC_Problem_Case_Link__c> scprblm = new List<SC_Problem_Case_Link__c>();
    List<SC_Problem_Case_Link__c> scprblmo = new List<SC_Problem_Case_Link__c>();
    List<SC_Problem_Case_Link__c> scprblmc = new List<SC_Problem_Case_Link__c>();
     for (Case cs: Trigger.new)
    {
        Case oldLead = Trigger.oldMap.get(cs.Id);

        if (cs.Status == 'Tested' && Trigger.oldMap.get(oldLead .Id).Status=='Ready for Testing')
        { 
            Ids.add(cs.Id);
        }
        if (cs.Status == 'ReOpen')
        { 
            IdR.add(cs.Id);
        }
        if (cs.Status == 'Closed')
        { 
            IdC.add(cs.Id);
        }
    }

    for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Ready for Testing' AND Case__c in :Ids])
    {

        if (rateSheet.Status__c != 'Tested') {
            rateSheet.Status__c = 'Tested';
            //rateSheet.Case__c.Status= 'Awaiting Deployment';
            scprblm.add(rateSheet);
        }

    }
    if (!scprblm.isEmpty()) {
        update scprblm;
    }


   for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Resolved' AND Case__c in :IdR])
    {
    // List<SC_Problem_Case_Link__c> accts = [Select Id, Status__c from SC_Problem_Case_Link__c where Id in : Trigger.old];

        if (rateSheet.Status__c != 'Open') {
            rateSheet.Status__c = 'Open';
            scprblmo.add(rateSheet);
        }

    }
    if (!scprblmo.isEmpty()) {
        update scprblmo;
    }


   for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Resolved' AND Case__c in :IdC])
    {

        if (rateSheet.Status__c != 'Closed') {
            rateSheet.Status__c = 'Closed';
            scprblmc.add(rateSheet);
        }

    }
    if (!scprblmc.isEmpty()) {
        update scprblmc;
    }
}
}
4

1 回答 1

0

嗨 SAdmin,欢迎来到社区。

您可以使用 Developer Console 来检查您的代码的哪一部分未包含在您的测试类中。每次运行测试类时,您都可以通过单击Code Coverage主 apex 类上的下拉菜单来查看覆盖了哪些代码行。

这样你就可以看到被测试覆盖的代码行是蓝色的。没有被覆盖的代码行是红色的。不需要覆盖的代码行(例如,大括号、注释和 System.debug 调用)留白。

请查看指南以查找更多信息。

于 2019-02-28T00:28:06.213 回答