Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am adding cookie to my page in the controller using ApexPages.currentPage().setCookies(new Cookie[]{CookieName});

When am trying to get the code coverage, my test class is not covering the above line.

How to get the code coverage for the above setcookie method in the test class.

share|improve this question
Are you using test.setCurrentPage(Page.vfpagename) in your unit test? – Force2b Aug 23 '12 at 13:41
Yes. But it has no effect. – Priyanka Aug 23 '12 at 13:49
Were you ever able to get this working? – turbo2oh Mar 21 at 15:05

1 Answer

I have no issue covering the following:

//name, value, path, maxAge, isSecure
Cookie cookie = new Cookie('name', 'value', null, -1, false);
ApexPages.currentPage().setCookies(new Cookie[]{cookie});

Do you have the test data set up such that the setCookies code will actually get executed? Add in a debug message before it and after it and then see them in the debug log.

Also, I've had the code coverage behave odd at times and I had to click the Compile All Classes link and then the Clear Code Coverage button, before executing the unit test again to get accurate code coverage. You might want to try that.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.