+ Start a Discussion
JkkJkk 

I am trying to cover the positive scenario of a class but i am receiving assetion fail error.

I am trying to cover the positive scenario of a class but i am receiving assetion fail error. Kindly help

Class:
 public class CTICallInitiationService {
 public static Id createServiceSessionRecord(String route, String callFrom, String customerType, String language, String branchPhone, String highestAuth, String trustedPhone){
        Service_Session__c serviceSessionRecord = new Service_Session__c(); 
        //serviceSessionRecord.Account_ID__c = accountId;
        serviceSessionRecord.Session_Type__c = 'Phone';        
        serviceSessionRecord.Highest_Authentication_Level_Achieved__c = highestAuth;       
        serviceSessionRecord.Authentication_Level__c = highestAuth;
        //serviceSessionRecord.Parent_Case__c=idCase;
        serviceSessionRecord.Created_Date_Time__c = System.now();
        serviceSessionRecord.Status__c = 'Active';
        serviceSessionRecord.Initiating_User__c = UserInfo.getUserId();
        serviceSessionRecord.Call_Route__c = route;
        serviceSessionRecord.Call_From_ANI__c = callFrom;
        serviceSessionRecord.Customer_type__c = customerType;
        serviceSessionRecord.Language__c = language;
        serviceSessionRecord.Branch_Phone__c = branchPhone;
        serviceSessionRecord.trusted_phone__c = trustedPhone;
        try {
            insert serviceSessionRecord;
        } catch(DmlException e) {
            serviceSessionRecord.id = null;
            System.debug('The following exception has occurred: ' + e.getMessage());
        }
        return serviceSessionRecord.id;
        }
        }
    
Test Class:

@isTest(seeAllData=false)

private class CtiCallInitiationServiceTest {

    
     @isTest
    private static void ServiceSessionRecordTest(){
        /* Positive insertion */
        Id idSession1 = CtiCallInitiationService.createServiceSessionRecord('route', 'callFrom' , 'customerType' , 'language' , 'branchPhone' , 'highestAuth' , 'trustedPhone');
           /* Negative insertion */      
        Id idSession2 = CtiCallInitiationService.createServiceSessionRecord('test', '9080942889' , 'Consumer' , 'Test' , '9080942889' , 'Full' , 'Yes');
        
        Test.startTest(); 
        system.assertEquals(False, String.isBlank(idSession1));
           system.assertEquals(true, String.isBlank(idSession2));
        Test.stopTest();
    }
    
}
Raj VakatiRaj Vakati
try like this
 
@isTest(seeAllData=false)

private class CtiCallInitiationServiceTest {
    
     @isTest
    private static void ServiceSessionRecordTest(){
        /* Positive insertion */
        Id idSession1 = CtiCallInitiationService.createServiceSessionRecord('route', 'callFrom' , 'customerType' , 'language' , 'branchPhone' , 'highestAuth' , 'trustedPhone');
           /* Negative insertion */  
Id idSession2 =''; 	
try{	   
         idSession2 = CtiCallInitiationService.createServiceSessionRecord('test', '9080942889' , 'Consumer' , 'Test' , '9080942889' , 'Full' , 'Yes');
}catch(Exception e){
}
			Test.startTest(); 
			system.assertEquals(False, String.isBlank(idSession1));
           system.assertEquals(true, String.isBlank(idSession2));
        Test.stopTest();
    }
    
}

 
JkkJkk
@Raj Vakati : but i need to keep idSession1 for positive case scenario
Raj VakatiRaj Vakati
Change it as below
 
@isTest(seeAllData=false)

private class CtiCallInitiationServiceTest {
    
     @isTest
    private static void ServiceSessionRecordTest(){
        /* Positive insertion */
        Id idSession1 = CtiCallInitiationService.createServiceSessionRecord('route', 'callFrom' , 'customerType' , 'language' , 'branchPhone' , 'highestAuth' , 'trustedPhone');
           /* Negative insertion */  
Id idSession2 =''; 	
try{	   
         idSession2 = CtiCallInitiationService.createServiceSessionRecord('test', '9080942889' , 'Consumer' , 'Test' , '9080942889' , 'Full' , 'Yes');
}catch(Exception e){
}
			Test.startTest(); 
			system.assertEquals(False, String.isBlank(idSession2));
           system.assertEquals(true, String.isBlank(idSession1));
        Test.stopTest();
    }
    
}