+ Start a Discussion
decentshaildecentshail 

Test method coverage: param not covered.

Hi All,

     I have to covered my apex class but there is issue due to param value setting

                         <apex:commandLink style="color:blue" action="{!ResubmitRequest}">Resubmit
<apex:param name="role" value="{!t1.Name}"/>
</apex:commandLink>

in apex code we getting the values as - 

public string change = ApexPages.currentPage().getParameters().get('role');

and now query on a object based on change condition.

 

i have my test method-

           PageReference pageRef = Page.myVFPage;
           ApexPages.currentPage().getParameters().put('role', testObj.Name);
           Test.setCurrentPage(pageRef);
           ApexPages.StandardController thecontroller = new ApexPages.StandardController(testFO);          
           CoverageHistory controller = new CoverageHistory(thecontroller);
controller.ResubmitRequest();


Issue is change values always getting null value.

shra1_devshra1_dev

Did you check whether you are getting the value for testObj.Name in the Test Class? Test it by placing the debug statement in test Class.

           PageReference pageRef = Page.myVFPage;
           ApexPages.currentPage().getParameters().put('role', testObj.Name);
           system.debug(testObj.Name);
           Test.setCurrentPage(pageRef);
           ApexPages.StandardController thecontroller = new ApexPages.StandardController(testFO);          
           CoverageHistory controller = new CoverageHistory(thecontroller);
           controller.ResubmitRequest();

 Regards,

Shravan

Shashikant SharmaShashikant Sharma

any param from visualforce page in test method is not set like 

PageReference pageRef = Page.myVFPage;
           ApexPages.currentPage().getParameters().put('role', testObj.Name);
           

 Instead we create a scenario similar to end user by assigning a value to param assigned to value in your case value attribute , like this

PageReference pageRef = Page.myVFPage;
           // here just assigned this like when user will click on command link it will be passed
           testObj.Name = 'New Test Name';
           Test.setCurrentPage(pageRef);
           ApexPages.StandardController thecontroller = new ApexPages.StandardController(testFO);          
           CoverageHistory controller = new CoverageHistory(thecontroller);
           controller.ResubmitRequest();

 let me ask if any issue in it.