Create Handler Methods

You can create test codeunits, test methods, and test pages to test your application. We recommend that you create tests that can be automated. To create automated tests, you must write code to handle all UI interactions so that the tests don't require user interaction when they're running. To do this, you create special handler methods.

You can use the following handler methods:

Method type Purpose Signature
MessageHandler Handles Message statements. <Function name>(<Message>: Text[1024])
ConfirmHandler Handles Confirm statements. <Function name>(<Question>: Text[1024]; var <Reply>: Boolean)
StrMenuHandler Handles StrMenu statements. <Function name>(<Options: Text[1024]; var <Choice>: Integer; <Instruction>: Text[1024])
PageHandler Handles specific pages that aren't run modally. <Function name>(var <Page>: Page <page id>)

<Function name>(var <Page>: TestPage <testpage id>)
ModalPageHandler Handles specific pages that are run modally. <Function name>(var <Page>: Page <page id>; var <Response>: Action)

<Function name>(var <Page>: Page <testpage id>)
ReportHandler Handles specific reports. If you create a ReportHandler method, then that method replaces all code for running the report, including the request page, and a RequestPageHandler isn't called. Only create a RequestPageHandler if you aren't using a ReportHandler. <Function name>(var <Report>: Report <report id>)
FilterPageHandler Handles a specific filter page. The FilterPageHandler tests the UI that is generated by a FilterPageBuilder Data Type. <Function name>(var <Record1>: RecordRef)[, var <Record2>: RecordRef] [, ...]): Boolean
RequestPageHandler Handles the request page of a specific report. <Function name>(var <RequestPage>: TestRequestPage)
HyperlinkHandler Handles specific hyperlinks. <Function name>(<Hyperlink>: Text[1024])
SendNotificationHandler Handles Send statements. <Function name>(<TheNotification>: Notification): Boolean
RecallNotificationHandler Handles Recall statements. <Function name>(<TheNotification>: Notification): Boolean
SessionSettingsHandler Handles RequestSessionUpdate statements. <Function name>(var <SessionSettings>: SessionSettings): Boolean

How to create a handler method

To create a handler method, you set one of the handler attributes on a method. You must use the method signature specified for the handler attribute that you're using, as illustrated in this code example.

[MessageHandler]
procedure MessageHandler(Message: Text[1024])
begin
    Assert.IsTrue(StrPos(Message, MSG_HAS_BEEN_CREATED) > 0, Message);
end;

The parameters of the methods that are being handled are passed as parameters to the handler methods. For example, when Message is called in a test method, the parameter of the Message method is passed as the parameter of the MessageHandler method. For page and report handlers, the page, report, or request page is passed as the parameter of the PageHandler, ModalPageHandler, ReportHandler, or RequestPageHandler.

You can call handler methods from methods that have the Test Attribute and then specify the handler methods that it will use in the HandlerFunctions Attribute. The code inside the test method should simulate that the UI was actually raised and some values entered or some actions were taken. You can specify more than one handler method by separating the handler method names with a comma.

Note

Every handler method that you enter in the HandlerFunctions Attribute of a test method must be called at least one time in the test method. If you run a test method that has a handler method listed that isn't called, then the test fails.

The following example shows a test method that uses the HandlerFunctions Attribute to call the MessageHandler method.

[Test]
[HandlerFunctions('MessageHandler')]
procedure ApproveRequestForPurchCreditMemo()
var
    PurchHeader: Record "Purchase Header";
begin
    ApproveRequestForPurchDocument(PurchHeader."Document Type"::"Credit Memo");
end;

See Also

Testing the Application
AL Methods