You need to sign in to do that
Don't have an account?
Mohmad Sohel
Test class for Custom Controller
Hi, please help on writing test class for below controller:
public class DataTableExampleController {
public List<Contact> contactList{
get{
if(contactList ==Null){
contactList = [select Account.Name, FirstName, LastName, Phone from Contact limit 10000];
}
return contactList;
}
set;
}
}
Test class:
@isTest
public class Test_DataTableExampleController {
static testMethod void testSave(){
Test.setCurrentPage(Page.DataTablePage);
Account acc = new Account(Name = 'Test');
insert acc;
Contact con = new Contact(LastName = 'Test', AccountId = acc.Id );
insert con;
DataTableExampleController dt = new DataTableExampleController ();
// dt.contactList = 'test';
// System.assertEquals(contactList, 'test');
}
}
Thank You.
public class DataTableExampleController {
public List<Contact> contactList{
get{
if(contactList ==Null){
contactList = [select Account.Name, FirstName, LastName, Phone from Contact limit 10000];
}
return contactList;
}
set;
}
}
Test class:
@isTest
public class Test_DataTableExampleController {
static testMethod void testSave(){
Test.setCurrentPage(Page.DataTablePage);
Account acc = new Account(Name = 'Test');
insert acc;
Contact con = new Contact(LastName = 'Test', AccountId = acc.Id );
insert con;
DataTableExampleController dt = new DataTableExampleController ();
// dt.contactList = 'test';
// System.assertEquals(contactList, 'test');
}
}
Thank You.
Please assert the size of the contact list.
@isTest
public class Test_DataTableExampleController {
static testMethod void testSave(){
Test.setCurrentPage(Page.DataTablePage);
Account acc = new Account(Name = 'Test');
insert acc;
Contact con = new Contact(LastName = 'Test', AccountId = acc.Id );
insert con;
DataTableExampleController dt = new DataTableExampleController ();
System.assertEquals(dt.contactList.size(), 1);
}
}
All Answers
Please assert the size of the contact list.
@isTest
public class Test_DataTableExampleController {
static testMethod void testSave(){
Test.setCurrentPage(Page.DataTablePage);
Account acc = new Account(Name = 'Test');
insert acc;
Contact con = new Contact(LastName = 'Test', AccountId = acc.Id );
insert con;
DataTableExampleController dt = new DataTableExampleController ();
System.assertEquals(dt.contactList.size(), 1);
}
}