function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kamalpreet Bhatia 3Kamalpreet Bhatia 3 

I have written a test class, it is only covering 68% percent of the code. Please help to increase the code coverage

try{
            for(Case c : caseList){
                if(c.Timer__c >= 10){
                    c.IsEscalated = true;
                    c.Status = 'Escalated';
                    caseUpdateList .add(c);
                    system.debug(c);
                }
            }
            if(caseUpdateList .size()>0){
                update caseUpdatelist ;
                system.debug(' case is Escalated in 10 minutes');
            }
        }
        catch(exception ex){
            system.debug(' case is not updated, it is now working according the criteria');
        }

In the Above code it is not covering a if statements. Here timer__c is formula field .

Test Class:
 
@isTest(SeeAllData = true)
private class CaseEscalationTest {

	private static testMethod void caseEscalationTestMethod() {
	    
	    case c = new case();
	    c.status = 'New';
	    c.origin = 'Phone';
	    c.Type = 'Status of specimen';
	    c.IsEscalated = false;
	    
	    insert c;
	    c = [SELECT Status,Origin,Type,Timer__c FROM case WHERE Id = :c.Id];
	    //Datetime yesterday = Datetime.now().addDays(-1);
        //Test.setCreatedDate(c.Id, yesterday);
	    
	    case c1 = new case();
	    c1.status = 'New';
	    c1.origin = 'Phone';
	    c1.Type = 'Status of specimen';
	    c1.IsEscalated = true;
	    insert c1;
	    
	    Test.startTest();
	    scheduleOneMinute som = new scheduleOneMinute();
	    system.Schedule('Specimen Cases', '0 1 11 ? * *', som);
        Test.stopTest();
	}
		

}
 
 
karthik R 80karthik R 80
Hi KamalPreet Bhatia,

Insert case with the Timer__c with greater than 10 value and insert the case , if still doesn't gets then create a another method and try to insert the case which  satisfies the conditon and run it.
Ex: 
case c = new case();
	    c.status = 'New';
	    c.origin = 'Phone';
	    c.Type = 'Status of specimen';
	    c.IsEscalated = false;
            c.Timer__c=15;
	    
	    insert c;

if it helps you mark it as Best Answer 
Thanks ,
karthik
 
Sukanya BanekarSukanya Banekar
Hi KamalPreet,

Check the formula for Timer__c field and insert case according to that.

Hope this helps you.

Thanks,
Sukanya Banekar