function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Test Class content for apex mesdage



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');
return p;

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

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);
  PageReference pgRes =;
  System.assert(ApexPages.getMessages()[0].getSummary().contains('Please select'));


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?



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)