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
bonny mankotiabonny mankotia 

Stuck in Trigger Test Class

User-added image
Not able to cover the else block.Below is the test Class

@isTest
public class TestConTrigg 
{
    static testmethod void testFun()
    {
        account acc = new account();
        acc.name ='less';
        insert acc;
        
        contact con = new contact();
        con.lastname = 'ram';
        con.password__c = 'sdaf';
        con.Accountid = acc.Id;
        insert con;
        
        account acc1 = new account();
        acc1.name ='less';
        insert acc1;
        
        contact con1 = new contact();
        con1.Accountid = acc1.Id;
        con1.account.name = con1.lastname = ' ';
        con1.password__c = 'sdaqwe';
        update con1;
    }    
}
JeffreyStevensJeffreyStevens
That's because you need to also delete a Contact record in your test class.
Dan1126Dan1126
Your trigger will never fire on deletion, since you only have after insert and after update declared in the first line. So the Trigger.isDelete boolean will never be true. So change that and then, as Jeffrey said, delete a contact record in your test class. 
JeffreyStevensJeffreyStevens
Right - good catch