+ Start a Discussion
Kumar GKumar G 

Test class code coverage issue with trigger

I have written a test class for a trigger which is showing as per the below picture.
Below block(Mark as Red) of code is not covering please suggest me how to cover this block.
find my test class code below:
Trigger : 

trigger Updateincident on BMCServiceDesk__Incident__c (after insert, after update) 
{ 
    Map<ID, Case> parentCases = new Map<ID, Case>(); //Making it a map instead of list for easier lookup
    Set<ID> bmsdID = new Set<ID>();

    for(BMCServiceDesk__Incident__c childObj : Trigger.new) 
    {
        bmsdID.add(childObj.Cases__c);
    }

    parentCases = new Map<Id, Case>([SELECT id,Helpdesk_Case_Status__c,Helpdesk_Case_Resolution__c,
        (SELECT ID,Name, BMCServiceDesk__FKStatus__c,Owner.Name,BMCServiceDesk__Status_ID__c,BMCServiceDesk__incidentResolution__c FROM Incidents__r) FROM Case WHERE ID IN :bmsdID]);

    for(ID caseID : parentCases.keySet())
    {
        for(BMCServiceDesk__Incident__c incidents : parentCases.get(caseID).Incidents__r)
        {
            parentCases.get(caseID).Helpdesk_Case_Resolution__c = incidents.BMCServiceDesk__incidentResolution__c;
            parentCases.get(caseID).Helpdesk_Case_Status__c = incidents.BMCServiceDesk__Status_ID__c;
            parentCases.get(caseID).Incident_Owner__c = incidents.Owner.Name;
            parentCases.get(caseID).Incident_Number__c = incidents.Name;            
        }
    }

    update parentCases.values();
}


Test class :

@isTest
public class Updateincident_Test {
    static testMethod void UpdateIncidentTest() {    
        BMCServiceDesk__Category__c cat = new BMCServiceDesk__Category__c();
        cat.Name='SAR';
        cat.BMCServiceDesk__AvailableForIncidents__c=true;
        cat.BMCServiceDesk__inactive__c=false;
        insert cat;

        Case cs  = new Case();

        cs.Status = 'open';
        cs.Helpdesk_Case_Resolution__c = 'Test 123';
        cs.Helpdesk_Case_Status__c = 'Closed';
        cs.Incident_Owner__c = 'Naveen';
        cs.Incident_Number__c  = '12345';
        Insert cs;

        BMCServiceDesk__Incident__c inc = new BMCServiceDesk__Incident__c();
        inc.Assigned_Staff__c='005800000045QSjAAM';
        inc.Resolution_Summary__c='resolved';
        inc.Service_Request_Form_Type__c='SAR';
        inc.BMCServiceDesk__incidentDescription__c='FSJ SAR test 123';
        inc.Resource_Type__c='New Contractor';
        inc.Start_Date__c = Date.Today();
        inc.SRF_Location__c='Australia';
        inc.Cases__c = cs.id;
        inc.BMCServiceDesk__FKCategory__c=cat.Id;
        insert inc;
        Update Inc;
    }
 }



Test class
GhanshyamChoudhariGhanshyamChoudhari
BMCServiceDesk__Incident__c inc = new BMCServiceDesk__Incident__c();
        inc.Assigned_Staff__c='005800000045QSjAAM';
        inc.Resolution_Summary__c='resolved';
        inc.Service_Request_Form_Type__c='SAR';
        inc.BMCServiceDesk__incidentDescription__c='FSJ SAR test 123';
        inc.Resource_Type__c='New Contractor';
        inc.Start_Date__c = Date.Today();
        inc.SRF_Location__c='Australia';
        inc.Cases__c = cs.id;
        inc.BMCServiceDesk__FKCategory__c=cat.Id;
        insert inc;
		
		BMCServiceDesk__Incident__c bic = new BMCServiceDesk__Incident__c();
		bic.id=inc.id;
		bic.Start_Date__c = Date.Today()+1;
        Update bic;