[SalesForce] ‘AccountProcessorTest’ test class doesn’t appear to calling the ‘AccountProcessor.countContacts’ method between Test.startTest() and Test.stopTest()

I am doing Trailhead from : https://trailhead.salesforce.com/modules/asynchronous_apex/units/async_apex_future_methods and getting the below error.

enter image description here

AccountProcessor

public class AccountProcessor {
    @future
    public static void countContact(Set<Id> setId){
        List<Account> lstAccount = [select Id,Number_of_Contacts__c,(select id from contacts) from account where id in :setId];
        for(Account acc : lstAccount){
            List<Contact> lstCont = acc.contacts;
            acc.Number_of_Contacts__c = lstCont.size();
        }
        update lstAccount;
    }
}

AccountProcessorTest

@isTest
public class AccountProcessorTest {
    public static testMethod void testAccountProcessorTest(){
        Test.startTest();
        Account a = new Account();
        a.Name = 'Test Account';
        insert a;

        Contact cont = new Contact();
        cont.FirstName ='Bob';
        cont.LastName ='Masters';
        cont.AccountId = a.Id;
        insert cont;

        Set<Id> setAccId = new Set<ID>();
        setAccId.add(a.Id);

        AccountProcessor.countContact(setAccId);       

        Account acc = [select Number_of_Contacts__c from Account where id = :a.id LIMIT 1];
        System.assertEquals(Integer.valueOf(acc.Number_of_Contacts__c) ,1);
        Test.stopTest();
    } 
}

Best Answer

Change the method name from countContact to countContacts as mentioned in the specified trailhead module - Use Future Methods:

Create an Apex class called 'AccountProcessor' that contains a 'countContacts' method that accepts a List of Account IDs. This method must use the @future annotation.

Related Topic