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
padmini sspadmini ss 

Code coverage problems Passing & Receiving Parameters are not covered

Hi , i have 2 Vf pages and 2 Apex Controllers 
from first Vf page (Controller ) i am passing 2 parameters to another Vfpage(2nd controller)
i have problem with test coverage.
pls guide me..
these are the details of  vf pages as well as Controller classes

1st Vf page name: RevenuewithDateCriteria
Controller : RevenueDatev1
and the code which shoud be coverd:

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

2nd vf page: revenuewithdatecriteriainexcel
Controller : RevenuewithDatecriteriainExcel
and the code which shoud be coverd for this Search Function . ( Total Coverage : 70 % coverage : (  only  )
 

public  PageReference search() {
 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');  
.
.
.
.
.
.
}

And my test class is :
@isTest(SeeAllData=true)
private class TestRevenuewithDateCriteriav1 {
    static TestMethod void myUnitTestv1() {

/////// code coverage is 85% ////////////////

 PageReference pageRef = Page.RevenuewithDateCriteria;
           Test.setCurrentPage(pageRef);
            RevenueDatev1  controller = new RevenueDatev1();
             String nextPage = controller.movedatatoexcel().getUrl();
             
             ApexPages.currentPage().getParameters().put('MyVariable1', '2014-01-01');
             ApexPages.currentPage().getParameters().put('MyVariable2', '2014-12-31');
          
          RevenueDatev1 rdate = new RevenueDatev1 ();
          rdate.fDate = date.valueof('2014-01-01');
          rdate.tDate = date.valueof('2013-01-01');
          
         
         rdate.mainlogic();
         rdate.search();
         rdate.getfetchRevenueByMonth();
         rdate.appendEmptyOpportunities();
         rdate.createRevenueByMonth();
         rdate.movedatatoexcel();
--------------------------------------------------------------------------------

/////////////////////////////////////////////////////////////
This is testclass for my 2nd vf page and contrller 
ONLY 70% Coverage this is the test class
/////////////////////////////////////////////////////////////

PageReference pageRe = Page.revenuewithdatecriteriainexcel;
           Test.setCurrentPage(pageRe);
            RevenuewithDatecriteriainExcel  controller1 = new RevenuewithDatecriteriainExcel();
 revenuewithdatecriteriainexcel  r = new revenuewithdatecriteriainexcel ();
          r.fDate = date.valueof('2014-01-01');
          r.tDate = date.valueof('2013-01-01');
          
         
         r.mainlogic();
         r.search();
         r.getfetchRevenueByMonth();
         r.appendEmptyOpportunities();
         r.createRevenueByMonth();
.
.
.
.
===========================================

 
Vishnu VaishnavVishnu Vaishnav
Hey you can try this one ..

@isTest(SeeAllData=true)
private class TestRevenuewithDateCriteriav1 {
    static TestMethod void myUnitTestv1() {
    
        RevenueDatev1 rdate = new RevenueDatev1 ();
        rdate.fDate = date.valueof('2014-01-01');
        rdate.tDate = date.valueof('2013-01-01');
        rdate.mainlogic();
        rdate.search();
        rdate.getfetchRevenueByMonth();
        rdate.appendEmptyOpportunities();
        rdate.createRevenueByMonth();
        rdate.movedatatoexcel();

        ApexPages.currentPage().getParameters().put('MyVariable1', '2014-01-01');
        ApexPages.currentPage().getParameters().put('MyVariable2', '2014-12-31');
        revenuewithdatecriteriainexcel  r = new revenuewithdatecriteriainexcel ();
        r.search();
        r.fDate = date.valueof('2014-01-01');
        r.tDate = date.valueof('2013-01-01');
        r.mainlogic();
        r.getfetchRevenueByMonth();
        r.appendEmptyOpportunities();
        r.createRevenueByMonth();
    }
}