0
public class EmailDistributerTemplate
{
    public Id accountId {get;set;}

    public list<account> getLocation()
    {
        list<account> locationadd;
        locationadd=[select id,Phone,(select Street_1__c,City__c,State_Province__c,ZipCode__c,County__c FROM Addressbook__r WHERE Primary_Address__c = TRUE) from account where id =:accountId ];
                                                       
                                                                                                             
        return locationadd;
    }
}   
@isTest
public class EmailDistributerTemplateTest {
    
    @istest static void test_emailDistributer()
        
    {
        Account accRec = new Account(Name = 'Test Account', Territory_Code__c ='North',COG_Clinic_Type__c ='zoo');
        insert accRec;
        
        id accountId = acc.id;
        
        Addressbook__r  address = new LocationAddress__c(Street_1__c = 'Uk',State_Province__c = 'South',ZipCode__c='400101',County__c='California',Account__c = acc.Id;);
        insert address
        
        
    }

}

2 Answers 2

1

you don't call the method EmailDistributerTemplate.getLocation

Thats why you don't get coverage for it.

1
  • Non static method cannot be referenced from a static context: List<Account> EmailDistributerTemplate.getLocation() Apr 30, 2021 at 13:42
0

Your method is not static, so you need to create an instance of your class in the unit test.

EmailDistributerTemplate controller = new EmailDistributerTemplate();
controller.accountId = acc.Id;
Account[] results = EmailDistributerTemplate.getLocation();

This should be done after creating the test data (the code you've already written).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .