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
Charni Wiggins 9Charni Wiggins 9 

test class - add assertion, check account record type according to Lead field

Hi,

There is one class I am trying to increase code coverage for. I am an admin so am struggling a little! Would appreciate any help! I need to add an assertion (I think), to check the account record type, after the test ends. These lines in the class are not covered. 
The class converts all leads and sets the acc record type according to a custom lead field. 

Test class:
 
/***********************************************************************************************************************
Date       : 20-03-16
Description: This is the test class for handler class and Lead Trigger
- Data validation for all types of leads , Relating to contacts and accounts based on Email and Company
- Creating Centre Visits for Vistor Registraion Type
- Creating Events and Event Registartion for Event brite
*************************************************************************************************************************/


@isTest
private Class LeadTriggerHandler_Test
{

    private static TestMethod void createLead()
    {
        Profile p = [SELECT Id FROM Profile WHERE Name='XXX'];

        User u = new User(Alias = 'standt', Email='standarduser34@testorg.com',EmailEncodingKey='UTF-8', LastName='Tester', LanguageLocaleKey='en_US',LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='standarduser34@testorg.com');
        
        System.runAs(u) {

        Test.startTest();
        Lead_Source__c source=new Lead_Source__c(); // Checking for Lead Source
        source.Name ='Pitstop';
        insert source;
        
        Camapaign_Location__c location=new Camapaign_Location__c(); // Campaign Location 
        location.Name ='London newsletter';
        location.Location__c ='london';
        insert location;
        
        List<Account> lstAccount=new List<Account>();
        for(Integer i=0;i<4;i++)
        {    
            Account acc=new Account(Name ='demo'+i);
            lstAccount.add(acc);
        }
        insert lstAccount;
        
        List<Contact> lstContact=new List<Contact>();
        for(Integer i=0;i<1;i++)
        {    
            Contact c=new Contact(FirstName = 'test', LastName = 'test', Email = 'test@test.com', AccountId = lstAccount[0].Id);
            lstContact.add(c);
        }
        insert lstContact;
        
        
        List<Account_Names__c> lstAccNames=new List<Account_Names__c>();
        Account_Names__c defaultaccName=new Account_Names__c(Name ='Default',Id__c =lstAccount[0].Id);
        Account_Names__c digitalaccName=new Account_Names__c(Name ='Digital C Visitors',Id__c =lstAccount[1].Id);
        lstAccNames.add(defaultaccName);
        lstAccNames.add(digitalaccName);
        
        insert lstAccNames;
        
        
        Campaign campaign=new Campaign();
        campaign.Name = 'London newsletter';
        insert campaign;
        
        
        DC_Events__c events=new DC_Events__c(Event_Brite_ID__c ='1234',Name ='test');
        insert events;
        
        
        List<Lead> lstLead=new List<Lead>();
        final String chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
        for(Integer i=0;i<3;i++)
        {
            Lead lead=new Lead();
            lead.LastName ='test'+chars.substring(i, i+1);
            lead.Email = 'test'+i+'@test.com';
            lead.FirstName ='testlead';
            lead.Company ='test'+i;
            lead.Company_turnover__c = 0;
            lead.numberofemployees = 0;
            lead.LeadSource ='Pitstop';
            if(i== 0)
            {
                lead.recordtypeId = Schema.SobjectType.Lead.getRecordTypeInfosByName().get('General Lead').getRecordTypeId();    
                lead.Visiting__c =UserInfo.getName();
                lead.Centre_Location__c ='london';
                lead.Newsletter_OptIn__c ='Yes';
                lead.Event_Location__c ='london';
            }else if(i==1 || i==2)
            {
                lead.recordtypeId = Schema.SobjectType.Lead.getRecordTypeInfosByName().get('General Lead').getRecordTypeId();
                if(i==1)
                {
                    lead.Eventbrite_ID__c ='1234';
                }else{
                    lead.Eventbrite_ID__c ='12345';
                }
                //lead.Event_Location__c ='london';
                lead.Centre_Location__c ='london';
                lead.Newsletter_OptIn__c ='Yes';
            }
            lstLead.add(lead);
        }
        
        Lead lead=new Lead();
        lead.firstName ='test';
        lead.LastName ='test';
        lead.Email = 'test@test.com';
        lead.Company ='NA';
        lead.Company_turnover__c = 5000000;
        lead.numberofemployees = 5;
        lead.LeadSource ='Pitstop';
        lead.RecordTypeId = Schema.SobjectType.Lead.getRecordTypeInfosByName().get('General Lead').getRecordTypeId();
        lstLead.add(lead);
        
        Lead lead1=new Lead();
        lead.firstName ='test';
        lead1.LastName ='test';
        lead1.Email = 'test@test.com';
        lead1.Company ='demo0';
        lead.Company_turnover__c = 9000000;
        lead.numberofemployees = 9;
        lead1.LeadSource ='Pitstop';
        lead1.Organisation_Type__c ='Public Sector';
        lstLead.add(lead1);
            
        Lead lead2=new Lead();
        lead.firstName ='test';
        lead1.LastName ='test';
        lead1.Email = 'test@test.com';
        lead1.Company ='demo1';
        lead.Company_turnover__c = 9000000;
        lead.numberofemployees = 9;
        lead1.LeadSource ='Pitstop';
        lead1.Organisation_Type__c ='Tech Startups and Scaleups';
        lstLead.add(lead2);
            
        Lead lead3=new Lead();
        lead.firstName ='test';
        lead1.LastName ='test';
        lead1.Email = 'test@test.com';
        lead1.Company ='demo2';
        lead.Company_turnover__c = 9000000;
        lead.numberofemployees = 9;
        lead1.LeadSource ='Pitstop';
        lead1.Organisation_Type__c ='Industry';
        lstLead.add(lead3);
            
        Lead lead4=new Lead();
        lead.firstName ='test';
        lead1.LastName ='test';
        lead1.Email = 'test@test.com';
        lead1.Company ='demo3';
        lead.Company_turnover__c = 9000000;
        lead.numberofemployees = 9;
        lead1.LeadSource ='Online Application';
        lead1.Organisation_Type__c ='Small or Medium Enterprise';
        lstLead.add(lead4);
        
        insert lstLead;
        Test.StopTest();
            
            
    }
  }
}

Thank you!!
Andrew GAndrew G
To give an informed answer, I would need to see the trigger handler code and probably the trigger (depending on its structure).

Asserts by themselves don't improve coverage.  Mutliple test methods generally increase coverage, especially if we want to then do some intelligent asserts.
I notice also the placement of the Test.StartTest() key word and I wonder if that is the best place for it.  And i assume the last 4 leads added are an extra after the orginal test class was created.

Regards
Andrew