+ Start a Discussion
Proposal ButtonProposal Button 

Test class

Hi I am bit confused in writting a test class for a controller. I called these controller in an component. Please help me out in writing a Test class for the following controller


public class CAFApprovalHistoryController {
    public String cafId {get;set;}
    public List<ProcessInstanceHistory> getApprovalSteps() {
      If (cafId != null) {
        CAF__c cafs = [Select Id, Name, CAPEX_Total__c, Off_Net_Circuit_Expense_Total__c, CAF_IRR__c, of_Revisions__c, Sales_Rep__c, Sales_Manager__c, Account__c, CAF_Title1_del__c, CAF_1__c, Products_Requested__c, Bandwidth__c, Notes_of_Consideration__c, CAF_Link__c, (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, IsPending, IsDeleted, Id, CreatedDate, CreatedById, Comments, ActorId From ProcessSteps order by SystemModstamp desc) from CAF__c where Id = :cafId];
        return cafs.ProcessSteps;
      return new List<ProcessInstanceHistory> ();


Here is my component



<apex:component controller="CAFApprovalHistoryController" access="global">
    <apex:attribute name="cafId" assignTo="{!cafId}" type="String" description="Id of the CAF"/>  
    <apex:dataTable value="{!approvalSteps}" var="step">
 <td width="30%"> <apex:column value="{!step.SystemModstamp}" headerValue="Date"/> </td>
 <td width="30%"> <apex:column value="{!step.StepStatus}" headerValue="Status"/> </td>
 <td width="30%"> <apex:column value="{!step.OriginalActorId}" headerValue="Assigned To"/> </td>
 <td width="30%"> <apex:column value="{!step.ActorID}" headerValue="Actual Approver"/> </td>
 <td width="30%"> <apex:column value="{!step.Comments}" headerValue="Comments"/> </td>



try this



private class testmydata{
    static testmethod void mymethod(){
        CAFApprovalHistoryController obj = new CAFApprovalHistoryController ();
        caf__c objcaf = new caf__c();
        objcaf.name = 'test';
        insert objcaf;
        obj.cafId = objcaf.id;
        static testmethod void mymethod2(){
        CAFApprovalHistoryController obj = new CAFApprovalHistoryController ();