You need to sign in to do that
Don't have an account?
Aryan Jha
why the test is getting 0%
@istest
public class AccountProcessorTest {
@istest
static void CountContactTest()
{
List<Account>accounts=new List<Account>();
for(Integer i=0;i<300;i++)
{
accounts.add(new Account(Name='test account'+i));
}
insert accounts;
List<Contact>contacts=new List<Contact>();
List<Id>accountId=new List<Id>();
for(Account a:accounts)
{
contacts.add(new Contact(Firstname=a.name,Lastname='testname',AccountId=a.id));
accountId.add(a.id);
}
insert contacts;
Test.startTest();
AccountProcessor.countContacts(accountId);
Test.stopTest();
List<Account>accs=[SELECT Id,Number_Of_Contacts__c FROM Account];
for(Account acc:accs)
{
system.assertEquals(1,acc.Number_Of_Contacts__c);
}
}
}
public class AccountProcessorTest {
@istest
static void CountContactTest()
{
List<Account>accounts=new List<Account>();
for(Integer i=0;i<300;i++)
{
accounts.add(new Account(Name='test account'+i));
}
insert accounts;
List<Contact>contacts=new List<Contact>();
List<Id>accountId=new List<Id>();
for(Account a:accounts)
{
contacts.add(new Contact(Firstname=a.name,Lastname='testname',AccountId=a.id));
accountId.add(a.id);
}
insert contacts;
Test.startTest();
AccountProcessor.countContacts(accountId);
Test.stopTest();
List<Account>accs=[SELECT Id,Number_Of_Contacts__c FROM Account];
for(Account acc:accs)
{
system.assertEquals(1,acc.Number_Of_Contacts__c);
}
}
}
Can you mention the snippet you have implemented that you are testing using this class?
Thanks
Your code seems to be correct.
But the AccountPorcess apex class you have shown below in that class the parameter should be List<Id> accountsIds.
You should change and rerun the test class.
Hope it will pass and coverage will be above 90%.
Please mark it as the best answer if it helps you to fix the issue.
Thank and Regards,
Suraj Tripathi