+ Start a Discussion
sreekanth reddysreekanth reddy 

Test Class For Class

Hi All,
How to write test class for below class.
public class searchres {
public string country{get;set;}
public string PartneredNonPartneredUniversities{get;set;}
public string name{get;set;}
public string Qualification{get;set;}
public string quali{get;set;}
public string CourseCategory{get;set;}
public string Course{get;set;}
public string ProgramSepcialisation{get;set;}
public string Program{get;set;}

public list<SOV_Database__c> bank{get;set;}
Public SOV_Database__c ban{get;set;}
public id sh;
   public void login()
   {
       
       bank = [select id,country__c,qualification__c,Partnered_Non_Partnered_Universities__c,Course_Category__c,Program_Sepcialisation__c from SOV_Database__c where country__c=:country and Partnered_Non_Partnered_Universities__c=:PartneredNonPartneredUniversities ];
   }
   public List<SelectOption> getqualification()
   {
     List<SelectOption> options = new List<SelectOption>();
           
      Schema.DescribeFieldResult fieldResult =SOV_Database__c.qualification__c.getDescribe();
      List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
           
      for( Schema.PicklistEntry f : ple)
      {
         options.add(new SelectOption(f.getLabel(), f.getValue()));
      }       
      return options;
   }
   public List<SelectOption> getCourseCategory()
   {
     List<SelectOption> options = new List<SelectOption>();
           
      Schema.DescribeFieldResult fieldResult =SOV_Database__c.Course_Category__c.getDescribe();
      List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
           
      for( Schema.PicklistEntry f : ple)
      {
         options.add(new SelectOption(f.getLabel(), f.getValue()));
      }       
      return options;
   }
   public List<SelectOption> getProgramSepcialisation()
   {
     List<SelectOption> options = new List<SelectOption>();
           
      Schema.DescribeFieldResult fieldResult =SOV_Database__c.Program_Sepcialisation__c .getDescribe();
      List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
           
      for( Schema.PicklistEntry f : ple)
      {
         options.add(new SelectOption(f.getLabel(), f.getValue()));
      }       
      return options;
   }
}

Thanks
Pawan.
Vishal Negandhi 16Vishal Negandhi 16
Hi Pawan, 

Refer this blog to learn how to write a test class :
http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/

For the above class, I have written a test class code that should cover almost 100% code.
 
@isTest
public class Testsearchres{
	// first call the class constructor to invoke the class : I noticed your code doesn't have one though
	searchres controller = new searchres();
	
	// now call all getters
	controller.getqualification();
	controller.getCourseCategory();
	controller.getProgramSepcialisation();
	
	// call all the methods
	controller.login(); 
}

Ideally, you also need to create data in your test classes but just to give you a small idea on how to go about it, I have posted a code that should help you acheive good code coverage. 

Hope this helps :)