You need to sign in to do that
Don't have an account?
Tasia Demuth 4
Assertion failed error in test class
Hi all,
I am getting an assertion failed in the logs when I run the below test. I receive 100% coverage on this test. Any help you can provide to point me in the right direction, would be much appreciated.
Thanks!
Tasia
@isTest
public class UpdateCaseWhenLeadDeletedTest {
private static testMethod void LeadDeletedTest(){
//create a Lead
Lead lead=new Lead(LastName='Test',FirstName='Tester',Status='Known', Company = 'CD Test');
insert lead;
// create a Case
Case cscase=new Case(Status = 'New', Priority = 'Medium', Origin = 'Email');
cscase.Lead__c = lead.Id;
insert cscase;
//delete Lead
delete lead;
List<Case> lstCase = [SELECT id ,Status,Type FROM Case WHERE Lead__c =:lead.id ];
System.assert(lstCase.size() > 0 );
System.assertEquals('Denied', lstCase[0].Status);
System.assertEquals('Web Account Denied', lstCase[0].Type);
}
}
I am getting an assertion failed in the logs when I run the below test. I receive 100% coverage on this test. Any help you can provide to point me in the right direction, would be much appreciated.
Thanks!
Tasia
@isTest
public class UpdateCaseWhenLeadDeletedTest {
private static testMethod void LeadDeletedTest(){
//create a Lead
Lead lead=new Lead(LastName='Test',FirstName='Tester',Status='Known', Company = 'CD Test');
insert lead;
// create a Case
Case cscase=new Case(Status = 'New', Priority = 'Medium', Origin = 'Email');
cscase.Lead__c = lead.Id;
insert cscase;
//delete Lead
delete lead;
List<Case> lstCase = [SELECT id ,Status,Type FROM Case WHERE Lead__c =:lead.id ];
System.assert(lstCase.size() > 0 );
System.assertEquals('Denied', lstCase[0].Status);
System.assertEquals('Web Account Denied', lstCase[0].Type);
}
}
Did you want to test a trigger (ondelete for lead) ?
Otherwise the deletion of the lead will "nullify" the lead__c in Case by default.
delete Lead;
List<Case> lstCase = [SELECT id ,Status,Type FROM Case WHERE Lead__c = null ];
System.assert(lstCase.size() > 0 );
System.assertEquals('New', lstCase[0].Status); // or value changed by a trigger?
System.assertEquals(null, lstCase[0].Type); // or value changed by a trigger?
All Answers
Did you want to test a trigger (ondelete for lead) ?
Otherwise the deletion of the lead will "nullify" the lead__c in Case by default.
delete Lead;
List<Case> lstCase = [SELECT id ,Status,Type FROM Case WHERE Lead__c = null ];
System.assert(lstCase.size() > 0 );
System.assertEquals('New', lstCase[0].Status); // or value changed by a trigger?
System.assertEquals(null, lstCase[0].Type); // or value changed by a trigger?
I will try your above suggestion shortly!
Thanks,
Tasia