5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Apexのテストクラスでpage messageをテストしたいとき

Posted at

Apexのテストクラスでpage messageをテストしたいときのやり方メモ

正しいメッセージが出力されているかどうか確認したいときとかに使うと良いかも

やり方1

List<ApexPages.Message> messages = ApexPages.getMessages();
System.assertEquals(true, messages[0].getDetail().contains('hoge fuge'));

やり方2

List<ApexPages.Message> messages = ApexPages.getMessages();
System.assertEquals('hoge fuge', messages[0].getDetail());

エラーメッセージかどうか確認したいとき

List<ApexPages.Message> messages = ApexPages.getMessages();
System.assertEquals(ApexPages.Severity.ERROR, messages[0].getSeverity());
5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?