function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JerryhncJerryhnc 

Controller Test Coverage

I am new to writing test coverage and thought that I was starting with a simple code snippet.  What would the test coverage look like for the following code?
public class webinarController

{

private List<Podcast_SD__c> podcasts;

public List<Podcast_SD__c> getpodcasts()

{

podcasts = [Select Name, Link__c, Featured__c, Link_Name__c, Description__c, Episode_Number__c from Podcast_SD__c order by Episode_Number__c desc];

return podcasts;

}

private List<webinar__c> webinars;

public List<webinar__c> getwebinars()

{

webinars = [Select Name, Link__c, Featured__c, Link_Type__c, Title__c, Type__c, Year_QTR__c from Webinar__c order by Name asc];

return webinars;

}

Ankit AroraAnkit Arora
I can help you a little as actual database is with you, so your test class will look something like this. Please see my comments in class :

@isTest(SeeAllData = false)
private class webinarController_Test
{
	//Create your data here for Podcast_SD__c and from Webinar__c 
	//Am not sure which all fields are required so you have to do this

	Test.startTest() ;
	static testMethod void validateController()
	{
		webinarController con = new webinarController() ;
		List<Podcast_SD__c> lstProd = con.getpodcasts() ;
		List<webinar__c> lstWeb = con.getwebinars() ;
		//Try to apply asserts
	}
	Test.stopTest() ;
}

Also, please take a look on below links so you can learn better how to write a test class. It contains positive, negetive test cases etc.. My TestClass is very basic.

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_test.htm
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_best_practices.htm
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
Denis VakulishinDenis Vakulishin
And i can suggest you to implement pagination in your page and controller, because you retrieve all objects(without filtering) from database it could be slow and user unfriendly. In the case of many objects you could reach the limits.
Simple example is like 
public class webinarController

{
private Integer mPageNumber = 0;
private static final Integer PAGE_ITEMS_COUNT=50;
private List<Podcast_SD__c> podcasts;
private Integer CurrenOffset{
   get{ return offset = mPageNumber *PAGE_ITEMS_COUNT;}
}
public List<Podcast_SD__c> getpodcasts()

{
   
   podcasts = [Select Name, Link__c, Featured__c, Link_Name__c, Description__c, Episode_Number__c from Podcast_SD__c order by Episode_Number__c desc LIMIT PAGE_ITEMS_COUNT OFFSET :CurrenOffset];

   return podcasts;

}


private List<webinar__c> webinars;

public List<webinar__c> getwebinars()

{

   webinars = [Select Name, Link__c, Featured__c, Link_Type__c, Title__c, Type__c, Year_QTR__c fr   om Webinar__c order by Name asc LIMIT PAGE_ITEMS_COUNT OFFSET :CurrenOffset];

   return webinars;

}
public PageReference nextPage(){
  mPageNumber++;
}
public PageReference prevPage(){
   if(mPageNumber!=0)
     mPageNumber--;
}

}

Also you should add Count properies for Webinar__c and  Episode_Number__c to avoid getting out of right bound of data.