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
Sudeep SinghSudeep Singh 

Why my test class is not increasing more than 73% after puting all correct data

Class :- 

public class AutoConvertLead {
@InvocableMethod
public static void assignLeads(List<Id> LeadIds) { 
    try{ 
        Map<String,Date> NameDOBMap = new Map<String,Date>();
        List<String> leadNames = new List<String>();
        List<Date> leadDOBs = new List<Date>();
        List<Database.LeadConvert> massLeadConvert = new List<Database.LeadConvert>();
        List<Account> accountsToUpdate = new List<Account>();
        List<Account> accountsToInsert = new List<Account>();
        List<Contract> contractsToInsert = new List<Contract>();
        Map<String,Account> nameDOBToAccountMap = new Map<String,Account>();
        Map<String,Account> newCreatedAccounts = new Map<String,Account>();
        Map<ID,Id> leadProductMap = new Map<Id,Id>();
        
        Id personAccountRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Person Account').getRecordTypeId();
        LeadStatus cLeadStatus = [SELECT Id,MasterLabel FROM LeadStatus WHERE isConverted = true LIMIT 1];  
        
       // List<Lead> leads = [SELECT Id,Name,LastName,FirstName,Email,Date_Of_Birth__c,Service__c,Ethnicity__c, Race__c,Gender__c FROM Lead WHERE Id IN :LeadIds];
       Map<Id,Lead> leadmap= new Map<Id,Lead>([SELECT Id,Name,LastName,FirstName,Email,Date_Of_Birth__c,Service__c,Ethnicity__c,MobilePhone, Race__c,Gender__c,City,Country,State,Street,PostalCode FROM Lead WHERE Id IN :LeadIds]);
       // for(Lead lead: leads) {
        for(Lead lead: leadmap.values()) {
            leadNames.add(String.valueOf(lead.Name));
            leadDOBs.add(lead.Date_Of_Birth__c);
            NameDOBMap.put(lead.Name, lead.Date_Of_Birth__c);
            leadProductMap.put(lead.Id,lead.Service__c);
        }
        
        Map<Id, Account> existingAccounts = new Map<Id, Account>([SELECT Id, PersonBirthdate, Name, PersonGender FROM Account WHERE Name IN :NameDOBMap.KeySet() AND PersonBirthdate IN :NameDOBMap.values()]);
        
        for(account acc: existingAccounts.values()){
            
        }
        //System.debug('Check 1'+existingAccounts);
        for(Account accc: existingAccounts.values()){
            nameDOBToAccountMap.put(accc.Name+accc.PersonBirthdate, accc);
        }
        
       // for(Lead ld : leads){
        for(Lead ld: leadmap.values()) {
            if(!nameDOBToAccountMap.containsKey(ld.Name+ld.Date_Of_Birth__c)){
                Account existingAccount = new Account();
                existingAccount.LastName = ld.LastName;
                existingAccount.FirstName = ld.FirstName;
                existingAccount.PersonEmail = ld.Email;
                existingAccount.PersonGender = ld.Gender__c;
                existingAccount.RecordTypeId =  personAccountRecordTypeId;
                existingAccount.Ethnicity__pc = ld.Ethnicity__c;
                existingAccount.Race__pc = ld.Race__c;
                existingAccount.PersonGender = ld.Gender__c;
                existingAccount.PersonBirthdate = ld.Date_Of_Birth__c;
                existingAccount.PersonHomePhone = ld.MobilePhone;
                accountsToInsert.add(existingAccount);
            }  
        }
        
        if(accountsToInsert.size()>0){
            insert accountsToInsert;
        }
        //system.debug('accountsToInsert'+accountsToInsert);
        
        for(account acc: accountsToInsert){
            newCreatedAccounts.put(acc.FirstName+acc.LastName, acc);
        }
        //system.debug('newCreatedAccounts'+newCreatedAccounts);
        //for(Lead lead : leads){
            for(Lead lead : leadmap.values()){
            //System.debug('Check 2');
            Database.LeadConvert LeadConvert = new Database.LeadConvert();
            LeadConvert.setLeadId(lead.Id);
            LeadConvert.setConvertedStatus(cLeadStatus.MasterLabel);
            LeadConvert.setDoNotCreateOpportunity(false);
            
            if(lead.Name != null && lead.Date_Of_Birth__c != null){                    
                if(nameDOBToAccountMap.containsKey(lead.Name+lead.Date_Of_Birth__c) && nameDOBToAccountMap.get(lead.Name+lead.Date_Of_Birth__c)!=Null){
                    //system.debug('existingAccount==>'+nameDOBToAccountMap.get(lead.Name+lead.Date_Of_Birth__c));
                    Account existingAccount = new Account();
                    existingAccount.Id = nameDOBToAccountMap.get(lead.Name+lead.Date_Of_Birth__c).id;
                    //system.debug('existingAccount'+existingAccount);
                    existingAccount.Ethnicity__pc = lead.Ethnicity__c;
                    existingAccount.Race__pc = lead.Race__c;
                    existingAccount.PersonGender = lead.Gender__c;
                    existingAccount.PersonHomePhone = lead.MobilePhone;
                    accountsToUpdate.add(existingAccount);
                    LeadConvert.setAccountId(existingAccount.Id);
                }
                else{
                    //system.debug('lead.Name+lead.Date_Of_Birth__c'+lead.FirstName+lead.LastName);
                    if(newCreatedAccounts.containskey(lead.FirstName+lead.LastName) && newCreatedAccounts.get(lead.FirstName+lead.LastName)!= Null){
                        LeadConvert.setAccountId(newCreatedAccounts.get(lead.FirstName+lead.LastName).Id);
                    }  
                }
                //System.debug('LeadConvert.getAccountId()'+LeadConvert.getAccountId()); 
                massLeadConvert.add(LeadConvert);
                //system.debug('massLeadConvert'+massLeadConvert);
            }
        }
        
        if(!accountsToUpdate.isEmpty()){
            //system.debug('accountsToUpdate'+accountsToUpdate);
            update accountsToUpdate;
            //system.debug('accountsToUpdate'+accountsToUpdate);
            
        }
        
        if(!massLeadConvert.isEmpty()){
            //system.debug('massLeadConvert'+massLeadConvert);
            List<Database.LeadConvertResult> lcr = Database.convertLead(massLeadConvert);
            for(Database.LeadConvertResult leadConvertResult : lcr) {
                //system.debug('leadConvertResult'+leadConvertResult);
                //system.debug('accountid'+existingAccounts.containskey(leadConvertResult.accountid));
                if(leadConvertResult.isSuccess() && !existingAccounts.containskey(leadConvertResult.accountid) ) {
                    Contract contract = new Contract();
                    contract.Status = 'Draft';
                    contract.AccountId = leadConvertResult.getAccountId();
                    contract.StartDate = system.today();
                    contract.ContractTerm = 12;
                    if(leadProductMap.containskey(leadConvertResult.getLeadId()) && leadProductMap.get(leadConvertResult.getLeadId())!=Null){
                        contract.Service__c = leadProductMap.get(leadConvertResult.getLeadId());
                    }
                    if(leadmap.containskey(leadConvertResult.getLeadId())  ) {
                            
                        contract.BillingCity= leadmap.get(leadConvertResult.getLeadId()).City;
                        contract.BillingState= leadmap.get(leadConvertResult.getLeadId()).State;
                        contract.BillingCountry = leadmap.get(leadConvertResult.getLeadId()).Country;
                        contract.BillingStreet=leadmap.get(leadConvertResult.getLeadId()).Street;
                        contract.BillingPostalCode=leadmap.get(leadConvertResult.getLeadId()).PostalCode;
                        contract.ShippingCity = leadmap.get(leadConvertResult.getLeadId()).City;
                        contract.ShippingState = leadmap.get(leadConvertResult.getLeadId()).State;
                        contract.ShippingCountry = leadmap.get(leadConvertResult.getLeadId()).Country;
                        contract.ShippingStreet = leadmap.get(leadConvertResult.getLeadId()).Street;
                        contract.ShippingPostalCode = leadmap.get(leadConvertResult.getLeadId()).PostalCode;

                    }
                    contractsToInsert.add(contract);
                }
            }
        }
        
        if(!contractsToInsert.isEmpty()){
            insert contractsToInsert;
        }
    }catch(Exception e){
        //System.debug('Error: '+e.getMessage()+ 'Line Number'+e.getLineNumber());
    }
}
}


Test Class:- 

@isTest
public class Test_AutoConvertLead {
    @isTest
    static void testAutoConvertLead()
    {
        String recordTypeId = Schema.getGlobalDescribe().get('Account').getDescribe().getRecordTypeInfosByName().get('Person Account').getRecordTypeId();
        Account acc= new Account(
        RecordTypeID=recordTypeId ,
        FirstName='Test FName',
        LastName='Test LName',
        PersonBirthdate = date.valueOf('1998-02-02') ,
        PersonGender = 'Male',
        PersonMailingStreet='test@yahoo.com',
        PersonMailingPostalCode='12345',
        PersonMailingCity='SFO',
        PersonEmail='test@yahoo.com',
        PersonHomePhone='1234567',
        PersonMobilePhone='12345678'   
        );        
        insert acc;
        
        Product2 p = new Product2();
        p.Name = 'Covid Test Kit';
        p.sstation__Msrp__c = 1;
        insert p;
        
        Lead ld = new lead();
        ld.LastName = 'test';
        ld.FirstName = 'class';
        ld.Email = 'test@gmail.com';
        ld.Date_Of_Birth__c = date.valueOf('1998-02-02') ;
        ld.Race__c = 'Asian';
        ld.Ethnicity__c = 'Hispanic or Latino';
        ld.Gender__c = 'Male';
        ld.Status = 'New';
        ld.Shipping_First_Name__c = 'test';
        ld.Shipping_Last_Name__c = 'class';
        ld.City = 'test';
        ld.Country = 'tes';
        ld.Street = 'test';
        ld.State = 'test';
        ld.PostalCode = '000000';
        ld.Service__c = p.Id;
        ld.MobilePhone = '9999999999';
        ld.Phone = '8888888888';
        insert ld;
        
        Account accc = new Account();
        accc.LastName = ld.LastName;
        accc.FirstName = ld.FirstName;
        accc.PersonEmail = ld.Email;
        //accc.PersonBirthdate = ld.Date_Of_Birth__c-3;
        accc.Race__pc = ld.Race__c;
        accc.Ethnicity__pc = ld.Ethnicity__c;
        accc.PersonGender = ld.Gender__c;
        accc.BillingCity = ld.City;
        accc.BillingCountry = ld.Country;
        accc.BillingPostalCode = ld.PostalCode;
        accc.BillingState = ld.State;
        accc.BillingStreet = ld.Street;
        accc.PersonHomePhone = ld.Phone;
        accc.PersonMobilePhone = ld.MobilePhone;
        insert accc;
        
  
        Contract cont = new Contract();
        cont.AccountId= accc.id;
        cont.StartDate=date.today();
        cont.ContractTerm=2;
        cont.Status='Draft';
        //cont.Pricebook2Id = standardPricebook.Id;
        //cont.Service__c = op.Id;
        //cont.Insurance__c = mp.Id;
        cont.BillingStreet = 'test';
        cont.BillingPostalCode = '759128';
        cont.BillingState = 'test';
        cont.BillingCity = 'test';
        cont.BillingCountry = 'test';
        cont.BillingLatitude = 20.296059;
        cont.BillingLongitude = 85.824539;
        cont.ShippingCity = 'test';
        cont.ShippingCountry = 'test';
        cont.ShippingPostalCode = '777777';
        cont.ShippingLatitude = 20.296059;
        cont.ShippingLongitude = 85.824539;
        cont.Service__c = p.Id;
        insert cont;
        
      
        {

            System.assert(True, 'ErrorMessage');
            
             }
        
        
        Test.startTest();
        Lead l = new Lead(LastName = 'Test Lead',
                     Company = 'Test Company',Race__c = 'Asian',Ethnicity__c = 'Hispanic or Latino'
                     );
        insert l;
        
        
        AutoConvertLead obj = new AutoConvertLead();
        //String CRON_EXP = '0 0 0 3 9 ? 2042';
        //system.schedule('Test status Check9', CRON_EXP, obj );
        AutoConvertLead.assignLeads(new List<String>{l.id});
        Test.stopTest();
        
  
        
        // For Schedulable AutoSubscriptionForOrderCreation
        
        
    }
          @isTest
    static void testAutoConvertLead2()
    {
        String recordTypeId = Schema.getGlobalDescribe().get('Account').getDescribe().getRecordTypeInfosByName().get('Person Account').getRecordTypeId();
        Account acc= new Account(
        RecordTypeID=recordTypeId ,
        FirstName='Lead',
        LastName='Test',
        PersonBirthdate = date.valueOf('1998-02-02') ,
        PersonGender = 'Male',
        PersonMailingStreet='test@yahoo.com',
        PersonMailingPostalCode='12345',
        PersonMailingCity='SFO',
        PersonEmail='test@yahoo.com',
        PersonHomePhone='1234567',
        PersonMobilePhone='12345678',
        BillingStreet = 'Test',
        BillingCity = 'Test',
        BillingState = 'Test',
        BillingPostalCode = 'Test',
        BillingCountry = 'Test'
        );        
        insert acc;
        Lead l2 = new Lead(LastName = 'Test', FirstName = 'Lead',
                     Company = 'Test Company',Race__c = 'Asian',Ethnicity__c = 'Hispanic or Latino', Date_Of_Birth__c = date.valueOf('1998-02-02')
                     );
        insert l2;
        AutoConvertLead.assignLeads(new List<String>{l2.id});
    }
    
}

Code coverage is only 74%
Best Answer chosen by Sudeep Singh
Sudeep SinghSudeep Singh
@isTest
public class Test_AutoConvertLead {
    @isTest
    static void testAutoConvertLead()
    {
        String recordTypeId = Schema.getGlobalDescribe().get('Account').getDescribe().getRecordTypeInfosByName().get('Person Account').getRecordTypeId();
        Account acc= new Account(
        RecordTypeID=recordTypeId ,
        FirstName='Test FName',
        LastName='Test LName',
        PersonBirthdate = date.valueOf('1998-02-02') ,
        PersonGender = 'Male',
        PersonMailingStreet='test@yahoo.com',
        PersonMailingPostalCode='12345',
        PersonMailingCity='SFO',
        PersonEmail='test@yahoo.com',
        PersonHomePhone='1234567',
        PersonMobilePhone='12345678'   
        );        
        insert acc;
        
        Product2 p = new Product2();
        p.Name = 'Covid Test Kit';
        p.sstation__Msrp__c = 1;
        insert p;
        
        Lead ld = new lead();
        ld.LastName = 'test';
        ld.FirstName = 'class';
        ld.Email = 'test@gmail.com';
        ld.Date_Of_Birth__c = date.valueOf('1998-02-02') ;
        ld.Race__c = 'Asian';
        ld.Ethnicity__c = 'Hispanic or Latino';
        ld.Gender__c = 'Male';
        ld.Status = 'New';
        ld.Shipping_First_Name__c = 'test';
        ld.Shipping_Last_Name__c = 'class';
        ld.City = 'test';
        ld.Country = 'tes';
        ld.Street = 'test';
        ld.State = 'test';
        ld.PostalCode = '000000';
        ld.Service__c = p.Id;
        ld.MobilePhone = '9999999999';
        ld.Phone = '8888888888';
        insert ld;
        
        Account accc = new Account();
        accc.LastName = ld.LastName;
        accc.FirstName = ld.FirstName;
        accc.PersonEmail = ld.Email;
        //accc.PersonBirthdate = ld.Date_Of_Birth__c-3;
        accc.Race__pc = ld.Race__c;
        accc.Ethnicity__pc = ld.Ethnicity__c;
        accc.PersonGender = ld.Gender__c;
        accc.BillingCity = ld.City;
        accc.BillingCountry = ld.Country;
        accc.BillingPostalCode = ld.PostalCode;
        accc.BillingState = ld.State;
        accc.BillingStreet = ld.Street;
        accc.PersonHomePhone = ld.Phone;
        accc.PersonMobilePhone = ld.MobilePhone;
        insert accc;
        
  
        Contract cont = new Contract();
        cont.AccountId= accc.id;
        cont.StartDate=date.today();
        cont.ContractTerm=2;
        cont.Status='Draft';
        cont.BillingStreet = 'test';
        cont.BillingPostalCode = '759128';
        cont.BillingState = 'test';
        cont.BillingCity = 'test';
        cont.BillingCountry = 'test';
        cont.BillingLatitude = 20.296059;
        cont.BillingLongitude = 85.824539;
        cont.ShippingCity = 'test';
        cont.ShippingCountry = 'test';
        cont.ShippingPostalCode = '777777';
        cont.ShippingLatitude = 20.296059;
        cont.ShippingLongitude = 85.824539;
        cont.Service__c = p.Id;
        insert cont;
 
        {
          System.assert(True, 'ErrorMessage');    
             }
        
 
        Test.startTest();
        Lead l = new Lead(LastName = 'Test Lead',
                     Company = 'Test Company',Race__c = 'Asian',Ethnicity__c = 'Hispanic or Latino', Date_Of_Birth__c = date.valueOf('1998-02-02')
                     );
        insert l;
        
        
        AutoConvertLead obj = new AutoConvertLead();
        //String CRON_EXP = '0 0 0 3 9 ? 2042';
        //system.schedule('Test status Check9', CRON_EXP, obj );
        AutoConvertLead.assignLeads(new List<String>{l.id});
        Test.stopTest();
    
        // For Schedulable AutoSubscriptionForOrderCreation
 
    }
          @isTest
    static void testAutoConvertLead2()
    {
        String recordTypeId = Schema.getGlobalDescribe().get('Account').getDescribe().getRecordTypeInfosByName().get('Person Account').getRecordTypeId();
        Account acc= new Account(
        RecordTypeID=recordTypeId ,
        FirstName='Lead',
        LastName='Test',
        PersonBirthdate = date.valueOf('1998-02-02') ,
        PersonGender = 'Male',
        PersonMailingStreet='test@yahoo.com',
        PersonMailingPostalCode='12345',
        PersonMailingCity='SFO',
        PersonEmail='test@yahoo.com',
        PersonHomePhone='1234567',
        PersonMobilePhone='12345678',
        BillingStreet = 'Test',
        BillingCity = 'Test',
        BillingState = 'Test',
        BillingPostalCode = 'Test',
        BillingCountry = 'Test'
        );        
        insert acc;
        
        
        Lead l2 = new Lead(LastName = 'Test', FirstName = 'Lead',
                     Company = 'Test Company',Race__c = 'Asian',Ethnicity__c = 'Hispanic or Latino', Date_Of_Birth__c = date.valueOf('1998-02-02')
                     );
        insert l2;
        AutoConvertLead.assignLeads(new List<String>{l2.id});
    }
   
}

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Sudeep,

Can you highlight which lines of code were not getting covered?

Thanks,
 
Sudeep SinghSudeep Singh
                   if(newCreatedAccounts.containskey(lead.FirstName+lead.LastName) && newCreatedAccounts.get(lead.FirstName+lead.LastName)!= Null){
                        LeadConvert.setAccountId(newCreatedAccounts.get(lead.FirstName+lead.LastName).Id);
                    }  
                }
-------
           Contract contract = new Contract();
                    contract.Status = 'Draft';
                    contract.AccountId = leadConvertResult.getAccountId();
                    contract.StartDate = system.today();
                    contract.ContractTerm = 12;
                    if(leadProductMap.containskey(leadConvertResult.getLeadId()) && leadProductMap.get(leadConvertResult.getLeadId())!=Null){
                        contract.Service__c = leadProductMap.get(leadConvertResult.getLeadId());
                    }
                    if(leadmap.containskey(leadConvertResult.getLeadId())  ) {
                            
                        contract.BillingCity= leadmap.get(leadConvertResult.getLeadId()).City;
                        contract.BillingState= leadmap.get(leadConvertResult.getLeadId()).State;
                        contract.BillingCountry = leadmap.get(leadConvertResult.getLeadId()).Country;
                        contract.BillingStreet=leadmap.get(leadConvertResult.getLeadId()).Street;
                        contract.BillingPostalCode=leadmap.get(leadConvertResult.getLeadId()).PostalCode;
                        contract.ShippingCity = leadmap.get(leadConvertResult.getLeadId()).City;
                        contract.ShippingState = leadmap.get(leadConvertResult.getLeadId()).State;
                        contract.ShippingCountry = leadmap.get(leadConvertResult.getLeadId()).Country;
                        contract.ShippingStreet = leadmap.get(leadConvertResult.getLeadId()).Street;
                        contract.ShippingPostalCode = leadmap.get(leadConvertResult.getLeadId()).PostalCode;

                    }
                    contractsToInsert.add(contract);
                }
            }
        }
        
        if(!contractsToInsert.isEmpty()){
            insert contractsToInsert;
        }
    }catch(Exception e){
        //System.debug('Error: '+e.getMessage()+ 'Line Number'+e.getLineNumber());
    }
}
}

Those line of codes are not covered

Thanks
Sudeep SinghSudeep Singh
@isTest
public class Test_AutoConvertLead {
    @isTest
    static void testAutoConvertLead()
    {
        String recordTypeId = Schema.getGlobalDescribe().get('Account').getDescribe().getRecordTypeInfosByName().get('Person Account').getRecordTypeId();
        Account acc= new Account(
        RecordTypeID=recordTypeId ,
        FirstName='Test FName',
        LastName='Test LName',
        PersonBirthdate = date.valueOf('1998-02-02') ,
        PersonGender = 'Male',
        PersonMailingStreet='test@yahoo.com',
        PersonMailingPostalCode='12345',
        PersonMailingCity='SFO',
        PersonEmail='test@yahoo.com',
        PersonHomePhone='1234567',
        PersonMobilePhone='12345678'   
        );        
        insert acc;
        
        Product2 p = new Product2();
        p.Name = 'Covid Test Kit';
        p.sstation__Msrp__c = 1;
        insert p;
        
        Lead ld = new lead();
        ld.LastName = 'test';
        ld.FirstName = 'class';
        ld.Email = 'test@gmail.com';
        ld.Date_Of_Birth__c = date.valueOf('1998-02-02') ;
        ld.Race__c = 'Asian';
        ld.Ethnicity__c = 'Hispanic or Latino';
        ld.Gender__c = 'Male';
        ld.Status = 'New';
        ld.Shipping_First_Name__c = 'test';
        ld.Shipping_Last_Name__c = 'class';
        ld.City = 'test';
        ld.Country = 'tes';
        ld.Street = 'test';
        ld.State = 'test';
        ld.PostalCode = '000000';
        ld.Service__c = p.Id;
        ld.MobilePhone = '9999999999';
        ld.Phone = '8888888888';
        insert ld;
        
        Account accc = new Account();
        accc.LastName = ld.LastName;
        accc.FirstName = ld.FirstName;
        accc.PersonEmail = ld.Email;
        //accc.PersonBirthdate = ld.Date_Of_Birth__c-3;
        accc.Race__pc = ld.Race__c;
        accc.Ethnicity__pc = ld.Ethnicity__c;
        accc.PersonGender = ld.Gender__c;
        accc.BillingCity = ld.City;
        accc.BillingCountry = ld.Country;
        accc.BillingPostalCode = ld.PostalCode;
        accc.BillingState = ld.State;
        accc.BillingStreet = ld.Street;
        accc.PersonHomePhone = ld.Phone;
        accc.PersonMobilePhone = ld.MobilePhone;
        insert accc;
        
  
        Contract cont = new Contract();
        cont.AccountId= accc.id;
        cont.StartDate=date.today();
        cont.ContractTerm=2;
        cont.Status='Draft';
        cont.BillingStreet = 'test';
        cont.BillingPostalCode = '759128';
        cont.BillingState = 'test';
        cont.BillingCity = 'test';
        cont.BillingCountry = 'test';
        cont.BillingLatitude = 20.296059;
        cont.BillingLongitude = 85.824539;
        cont.ShippingCity = 'test';
        cont.ShippingCountry = 'test';
        cont.ShippingPostalCode = '777777';
        cont.ShippingLatitude = 20.296059;
        cont.ShippingLongitude = 85.824539;
        cont.Service__c = p.Id;
        insert cont;
 
        {
          System.assert(True, 'ErrorMessage');    
             }
        
 
        Test.startTest();
        Lead l = new Lead(LastName = 'Test Lead',
                     Company = 'Test Company',Race__c = 'Asian',Ethnicity__c = 'Hispanic or Latino', Date_Of_Birth__c = date.valueOf('1998-02-02')
                     );
        insert l;
        
        
        AutoConvertLead obj = new AutoConvertLead();
        //String CRON_EXP = '0 0 0 3 9 ? 2042';
        //system.schedule('Test status Check9', CRON_EXP, obj );
        AutoConvertLead.assignLeads(new List<String>{l.id});
        Test.stopTest();
    
        // For Schedulable AutoSubscriptionForOrderCreation
 
    }
          @isTest
    static void testAutoConvertLead2()
    {
        String recordTypeId = Schema.getGlobalDescribe().get('Account').getDescribe().getRecordTypeInfosByName().get('Person Account').getRecordTypeId();
        Account acc= new Account(
        RecordTypeID=recordTypeId ,
        FirstName='Lead',
        LastName='Test',
        PersonBirthdate = date.valueOf('1998-02-02') ,
        PersonGender = 'Male',
        PersonMailingStreet='test@yahoo.com',
        PersonMailingPostalCode='12345',
        PersonMailingCity='SFO',
        PersonEmail='test@yahoo.com',
        PersonHomePhone='1234567',
        PersonMobilePhone='12345678',
        BillingStreet = 'Test',
        BillingCity = 'Test',
        BillingState = 'Test',
        BillingPostalCode = 'Test',
        BillingCountry = 'Test'
        );        
        insert acc;
        
        
        Lead l2 = new Lead(LastName = 'Test', FirstName = 'Lead',
                     Company = 'Test Company',Race__c = 'Asian',Ethnicity__c = 'Hispanic or Latino', Date_Of_Birth__c = date.valueOf('1998-02-02')
                     );
        insert l2;
        AutoConvertLead.assignLeads(new List<String>{l2.id});
    }
   
}
This was selected as the best answer