Find your content:

Search form

You are here

Test coverage for setCookies method


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.

Attribution to: Priyanka

Possible Suggestion/Solution #1

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.

Attribution to: Peter Knolle
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content