+ Start a Discussion
cooldamselcooldamsel 

Test Class content for apex mesdage

Hi,

 

Can anyone please suggest me how to write a test class for the apex message content.

 

This is my code:

 

pagereference p = apexpages.Currentpage();
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Please select Report type, Year & Month');
apexpages.addmessage(msg);
return p;

crop1645crop1645
// Assuming you have a VF page Foo, controllerExtension FooControllerExtension on custom object Foo__c and your extendedmethod is called bar()

@isTest
private static void testFoo() {
  Foo__c foo = new Foo__c(name='bar');
  insert foo;
  ApexPages.StandardController ctlr   = new ApexPages.StandardController(foo);
  FooControllerExtension ext = new FooControllerExtension (ctlr);
  Test.setCurrentPage(Page.Foo);
  
  PageReference pgRes = ext.bar();
  System.assert(ApexPages.getMessages()[0].getSummary().contains('Please select'));
} 

 

cooldamselcooldamsel
I have a VF page Recruiter_Performance_Report and my controller class for this page is RecruiterPerformanceReport. In this controller class am creating instance for few other classes and using the methods in the other class. So can you please suggest me how to do this?
crop1645crop1645

Indhu

 

Please post an abbreviated version of the code that you are trying to accomplish (controller class, other class). Forum responders work best with just the relevant elements, not hundreds of lines of code to wade though)