I have created getContent() method to send a pdf page in email using Visualforce page. But while running test method on the controller, I am getting following error message - "Methods defined as TestMethod do not support getContent call, test skipped" How to fix this problem. Thank you in advance.
There's a few ways to do this. My personal preference is to generate a different Blob for the body of the page depending on whether my code is running in the test context:
So if I have a reference to the page in variable pr:
Blob content;
if (Test.IsRunningTest())
{
content=Blob.valueOf('UNIT.TEST');
}
else
{
content=pr.getContent();
}
and then do whatever I need to do with the body content.
-
17I'd suggest making it a one-line for test coverage purposes. Something like:
Blob content = Test.isRunningTest() ? Blob.valueOf('UNIT.TEST') : pr.getContent();
That way, it'll cover if you could get the content or not. – Programmable Medley Mar 9 '15 at 13:46