Tuesday 21 August 2012

Test for Apex Page Messages in test code

Today I thought to write an assert code for Apex Page messages at any moment in test method.

Although it is very basic, but it is very common question for new developers as how to write assert code for Apex Page messages. So, here is the method which returns total number of ApexPage Messages generated during the code execution:

ApexPages.getMessages().size()

So, for assert purpose, one can use this:

System.assertEquals(ExpectedNumberOfPageMessages,ApexPages.getMessages().size());

No comments:

Post a Comment