You need to sign in to do that
Don't have an account?
Jkk
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();
}
}
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 Vakati
try like this
Jkk
@Raj Vakati : but i need to keep idSession1 for positive case scenario
Raj Vakati
Change it as below