0

How do i cover containskey() and keyset() method? i only cover 68% of my code. here's my class

enter image description here

here's my test class

@isTest
private class testCheckPickedLead{

static testMethod void myMassUpdate() 
{
    Test.startTest();
        //insert test lead
    Lead testLead = new Lead(LastName='test',Company='testcompany',OwnerId='00G90000002zs7H',Status='Open',Is_Picked__c=TRUE); 
    insert testLead;
    List<Task> listTask = new List<Task>();
    for(Integer i=0;i<16;i++){
        listTask.add(new Task(WhoId=testLead.id,Subject='Call '+i,Type='Unreached Call',Status='Completed'));  
    }
    insert listTask;

    map<Id, List<Task>> map1 = new map<Id, List<Task>>(); 
    for(Task t : listTask)
    {
        map1.put(t.WhoId, new List<Task>{t});
    }

         System.schedule('testBasicScheduledApex', '0 31 13 * * ?', new checkPickedLead());
         Test.stopTest();
    }

}
2
  • Are you sure that leadlist2 is not empty? Thos hardcoded id doesnt look well
    – kurunve
    Commented Mar 10, 2016 at 11:27
  • hey, your query on task is not returning any results. Since the number of elements in the query result list is zero => there is nothing to iterate on for the "SOQL FOR" loop. Hence the code doesn't go inside the for loop. Now because of that your map is empty too. Now your second for loop runs through the "keyset" of this map(which is empty), -> the keyset is again empty. Hence the code doesn't get inside that loop too.
    – Prajith
    Commented Mar 10, 2016 at 11:37

1 Answer 1

1

Please use the following line of code in line 12 of your test class it will result the query results for the for loop in your batch class.

listTask.add(new Task(WhoId=testLead.id,Subject='Call '+i,
                                        Type='Unreach Call',Status='Completed')); 

The issue is the mismatch of value in type Unreach Call

1
  • ahh yes, didn't see that. after i change it from 'Unreach' to 'Unreached Call' my code coverage become 100%. Thanks guys Commented Mar 11, 2016 at 3:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .