+ Start a Discussion
cooldamselcooldamsel 

[Urgent!!] Test class for custom controller

Hi,

 

I have a Custom controller class for my VF page. The controller class contains a page reference and in my page reference method, i have used methods of another custom controller. I have written a test class and it passed succesfully. But my code coverage was 48%. 

I have my controller class and test class below. Please help me..

 

Controller Class:

 


public with sharing class RecruiterPerformanceReport
{
// Gets the selected month from the page
public String getMonths { get; set; }

// Gets the selected year from the page
public String getYear { get; set; }

// Gets the selected report type from the page
public String getReportType { get; set; }

// Gets or sets the List of performance report.
public List<PerformanceReportClass> LstPerformanceReport {get;set;}

// Initializes a new instance of the RecruiterPerformanceReport class.
public RecruiterPerformanceReport()
{
}

 

// Gets the report details.
public PageReference GetReportDetails()
{
// Dispalys eror message
if(((Integer.valueOf(getReportType)) == 0) && ((Integer.valueOf(getYear)) == 0000) && ((Integer.valueOf(getMonths)) == 00))
{
pagereference p = apexpages.Currentpage();
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Please select Report type, Year & Month');
apexpages.addmessage(msg);
return p;
}
else if(((Integer.valueOf(getReportType)) == 0) && ((Integer.valueOf(getYear)) == 0000))
{
pagereference p = apexpages.Currentpage();
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Please select Report type & Year');
apexpages.addmessage(msg);
return p;
}
else if(((Integer.valueOf(getReportType)) == 0) && ((Integer.valueOf(getMonths)) == 00))
{
pagereference p = apexpages.Currentpage();
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Please select Report type & Month');
apexpages.addmessage(msg);
return p;
}
else if(((Integer.valueOf(getYear)) == 0000) && ((Integer.valueOf(getMonths)) == 00))
{
pagereference p = apexpages.Currentpage();
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Please select Year & Month');
apexpages.addmessage(msg);
return p;
}
else if(((Integer.valueOf(getReportType)) == 0))
{
pagereference p = apexpages.Currentpage();
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Please select Report Type');
apexpages.addmessage(msg);
return p;
}
else if(((Integer.valueOf(getYear)) == 0))
{
pagereference p = apexpages.Currentpage();
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Please select Year');
apexpages.addmessage(msg);
return p;
}
else if(((Integer.valueOf(getMonths)) == 0))
{
pagereference p = apexpages.Currentpage();
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Please select Month');
apexpages.addmessage(msg);
return p;
}
else
{
// Selects the report type to be displayed based on selection
if((Integer.valueOf(getReportType)) == 1)
{
AssignRequirementReportClass objAssignRequirementReportClass = new AssignRequirementReportClass();
LstPerformanceReport = objAssignRequirementReportClass.getRequirementsAssigned(getMonths, getYear);
}
else if((Integer.valueOf(getReportType)) == 2)
{
ResumesSubmittedReportClass objResumesSubmittedReportClass = new ResumesSubmittedReportClass();
LstPerformanceReport = objResumesSubmittedReportClass.getResumesSubmitted(getMonths, getYear);
}
else if((Integer.valueOf(getReportType)) == 3)
{
ResumesRejectedReportClass objResumesRejectedReportClass = new ResumesRejectedReportClass();
LstPerformanceReport = objResumesRejectedReportClass.getResumesRejected(getMonths, getYear);
}
else if((Integer.valueOf(getReportType)) == 4)
{
CandidatesAddedReportClass objCandidatesAddedReportClass = new CandidatesAddedReportClass();
LstPerformanceReport = objCandidatesAddedReportClass.getCandidatesAdded(getMonths, getYear);
}
return null;
}
}
}

 

Test Class:


@istest (SeeAllData=true)
class TestClassRecruiterPerformanceReport
{
static testmethod void testRecruiterPerformanceReport()
{
PageReference pageRef = Page.Recruiter_Performance_Report;
Test.setCurrentPage(pageRef);

RecruiterPerformanceReport rrs = new RecruiterPerformanceReport();


rrs.getReportType = '1';
rrs.getMonths = '09';
rrs.getYear = '2013';
rrs.GetReportDetails();

rrs.getReportType = '2';
rrs.getMonths = '09';
rrs.getYear = '2013';
rrs.GetReportDetails();

rrs.getReportType = '3';
rrs.getMonths = '09';
rrs.getYear = '2013';
rrs.GetReportDetails();

rrs.getReportType = '4';
rrs.getMonths = '09';
rrs.getYear = '2013';
rrs.GetReportDetails();

}

}

Best Answer chosen by Admin (Salesforce Developers) 
Sri549Sri549

Hi Cooldamsel,

This is the updated test class for provided test class 

@istest (SeeAllData=true)
  public class Test_RecruiterPerformanceReport
    {
    public static testmethod void RecruiterPerformanceReport()
        {    
        RecruiterPerformanceReport rrs = new RecruiterPerformanceReport();
        rrs.getReportType= '0';
        rrs.getMonths = '00';
        rrs.getYear = '0000';
        rrs.GetReportDetails(); 
                     
        rrs.getReportType = '0';
        rrs.getMonths = '09';
        rrs.getYear = '0000';
        rrs.GetReportDetails();
        
        rrs.getReportType = '0';
        rrs.getMonths = '00';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        
        rrs.getReportType = '3';
        rrs.getMonths = '00';
        rrs.getYear = '0000';
        rrs.GetReportDetails();
        
        rrs.getReportType = '0';
        rrs.getMonths = '09';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        
        rrs.getReportType = '0';
        rrs.getMonths = '09';
        rrs.getYear = '0';
        rrs.GetReportDetails();
        
        rrs.getReportType = '0';
        rrs.getMonths = '0';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        rrs.getReportType = '1';
        rrs.getMonths = '0';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        rrs.getReportType = '2';
        rrs.getMonths = '0';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        rrs.getReportType = '3';
        rrs.getMonths = '0';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        rrs.getReportType = '4';
        rrs.getMonths = '0';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        
                 
        }    
    }

 Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Srinivas
SFDC Certified Developer

 

 

 

 

 

All Answers

Sri549Sri549

Hi Cooldamsel,

This is the updated test class for provided test class 

@istest (SeeAllData=true)
  public class Test_RecruiterPerformanceReport
    {
    public static testmethod void RecruiterPerformanceReport()
        {    
        RecruiterPerformanceReport rrs = new RecruiterPerformanceReport();
        rrs.getReportType= '0';
        rrs.getMonths = '00';
        rrs.getYear = '0000';
        rrs.GetReportDetails(); 
                     
        rrs.getReportType = '0';
        rrs.getMonths = '09';
        rrs.getYear = '0000';
        rrs.GetReportDetails();
        
        rrs.getReportType = '0';
        rrs.getMonths = '00';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        
        rrs.getReportType = '3';
        rrs.getMonths = '00';
        rrs.getYear = '0000';
        rrs.GetReportDetails();
        
        rrs.getReportType = '0';
        rrs.getMonths = '09';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        
        rrs.getReportType = '0';
        rrs.getMonths = '09';
        rrs.getYear = '0';
        rrs.GetReportDetails();
        
        rrs.getReportType = '0';
        rrs.getMonths = '0';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        rrs.getReportType = '1';
        rrs.getMonths = '0';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        rrs.getReportType = '2';
        rrs.getMonths = '0';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        rrs.getReportType = '3';
        rrs.getMonths = '0';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        rrs.getReportType = '4';
        rrs.getMonths = '0';
        rrs.getYear = '2013';
        rrs.GetReportDetails();
        
                 
        }    
    }

 Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Srinivas
SFDC Certified Developer

 

 

 

 

 

This was selected as the best answer
cooldamselcooldamsel
Thank you!!!! It works fine!!!