Hi Kristiana,Please use below code for 100% code coverage without changes in your main class
if you need any assistanse, Please let me know!!@isTest
public class MyContactListControllerTest {
static testMethod void getContactsTest_Try(){
Account ac = new Account(Name='Name1');
Insert ac;
List<Account> acList = List<Account>();
//System.assertEquals(true,acList.size()>0);
Contact c=new Contact(
AccountId = ac.Id,
FirstName='fname',
LastName = 'lname',
Email = 'email@gmail.com',
Phone = '9743800309');
insert c;
MyContactListController.getContacts(acList[0].id);
//List<Case> case_Obj = [SELECT Id,CaseNumber,AccountId From Case WHERE AccountId=:acList[0].Id LIMIT 10];
MyContactListController.getContacts(acList[0].Id);
}
static testMethod void getContactsTest_Catch(){
Account ac = new Account(Name='Name1');
Insert ac;
List<Account> acList = List<Account>();
//System.assertEquals(true,acList.size()>0);
Contact c=new Contact(
AccountId = ac.Id,
FirstName='fname',
LastName = 'lname',
Email = 'email@gmail.com',
Phone = '9743800309');
insert c;
MyContactListController.getContacts(acList[0].id);
//List<Case> case_Obj = [SELECT Id,CaseNumber,AccountId From Case WHERE AccountId=:acList[0].Id LIMIT 10];
List<String> ids = new List<String>();
MyContactListController.getContacts(ids);
}
}
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
9 件の回答