+ Start a Discussion
padmini sspadmini ss 

test coverage , need to pass parameters in test class

this is my Vf page
 
<apex:page controller="RevenueDate" sidebar="False" docType="html-5.0" readOnly="true">           
    <apex:form id="dateren">    
   <apex:commandlink value="Export Excel" action="{!movedatatoexcel}" />
<!--<a href="/apex/RevenueByMonthInExcel2"> Export to Excel</a>-->
    <br></br>    <br></br>    <br></br>

And the Apex class
public without sharing class RevenueDate {

   public PageReference movedatatoexcel() {
       PageReference newPage = page.RevenuewithDatecriteriainExcel;
      newPage.getParameters().put('MyVariable1', string.valueof(fDate));
       newPage.getParameters().put('MyVariable2', string.valueof(tDate) );
        return newPage ;
    }

and the secod Apex class
public  PageReference search() {
                     Fjan =Tjan=jancol =FALSE;                     
                     Ffeb=Tfeb=febcol =FALSE;
                     Fmar=Tmar=marcol =FALSE; 
                     Faprl =Taprl=aprilcol =FALSE;
                     Fmay =Tmay=maycol =FALSE;
                      Fjun =Tjun=junecol =FALSE;
                     Fjul =Tjul=julycol =FALSE; 
                     Faug =Taug=augcol =FALSE;
                     Fsep=Tsep=sepcol =FALSE;
                     Foct =Toct=octcol =FALSE;
                     Fnov =Tnov=novcol =FALSE; 
                     Fdec =Tdec=deccol =FALSE;
      
         if((Apexpages.currentPage().getParameters().get('MyVariable1'))!=NULL)
            fDate = (Date.valueOf(Apexpages.currentPage().getParameters().get('MyVariable1')));
   
         else   
            fDate=date.valueof('2014-08-01');
 
         if((Apexpages.currentPage().getParameters().get('MyVariable2'))!=NULL) 
            tDate = (Date.valueOf(Apexpages.currentPage().getParameters().get('MyVariable2')));  
          
        else
            tDate=date.valueof('2015-3-31');  
  
            // fDate = (Date.valueOf(Apexpages.currentPage().getParameters().get('MyVariable1'))!=NULL?(Date.valueOf(Apexpages.currentPage().getParameters().get('MyVariable1'))):(date.valueof('2014-01-01')));
            //  tDate = Date.valueOf(Apexpages.currentPage().getParameters().get('MyVariable2'));

And this is my test classs
RevenuewithDatecriteriainExcel revenueexcel = new RevenuewithDatecriteriainExcel();
   
        revenueexcel.fDate  = null;
        revenueexcel.tDate = null;
         revenueexcel.mainlogic();
         revenueexcel.search();
         revenueexcel.getfetchRevenueByMonth();
         revenueexcel.appendEmptyOpportunities();
         revenueexcel.createRevenueByMonth();
         
        
       
        revenueexcel.fDate  = date.valueof('2014-01-01');
        revenueexcel.tDate = date.valueof('2014-12-31');
         revenueexcel.mainlogic();
         revenueexcel.search();
         revenueexcel.getfetchRevenueByMonth();
         revenueexcel.appendEmptyOpportunities();
         revenueexcel.createRevenueByMonth();

Now i nedd to pass the parmeters of Myvariable1, Myvariable2 in the test class to cover my test class
please help me

 
bob_buzzardbob_buzzard
You can add parameters for use in a test using the following:
ApexPages.CurrentPage().getParameters().put('Myvariable1', '<your value>');
make sure to add this code before you execute the search method.
kumar tanwarkumar tanwar
You can Put date Parameter in Current page Like.
Date Variable1 = date.ValueOf(System.Today()); 
ApexPages.CurrentPage().getParameters().put('Myvariable1', Variable1);