I have a custom visual force page which is throwing the error -
I have found the line which causes the error and know how to fix, but just need to write a test class which will recreate the error that is displayed on the visual force page. The test I have so far is this:
/*Test visualforce page with list with over a thousand select options*/
static testMethod void testOverAThousandEmailTemplates() {
List<EmailTemplate> templatesToInsert = new List<EmailTemplate>();
User u = [Select id, Username FROM User WHERE Username = 'blah' limit 1];
for(integer i = 0; i < 2000; i++) {
EmailTemplate testTemplates = Helper.CreateEmailTemplate('custom','body','subject', u, 'EmailTemplate' + string.valueof(i));
templatesToInsert.add(testTemplates);
}
insert templatesToInsert;
PageReference pageRef = Page.MyPage;
Test.setCurrentPage(pageRef);
//Sets controller up for testing
PageController controller = initialise();
}
This test works - I would expect that when I set the page reference the visualforce error would be thrown. How can I test this?
Update: I have tried getMessage() but no messages are being returned. I can't check the pages content as getContent() is disabled in tests. Even checking the URL won't work as the error page has the same URL as the valid page (checked in the GUI).