- Open your AL project in Visual Studio Code.
- In Explorer, select My Test.al and in the Editor, create a new test function:
[Test]
procedure TestConfirmHandler()
var
UiHandlerTest: TestPage "UI Handler Test";
begin
UiHandlerTest.OpenView();
UiHandlerTest.ConfirmTest.Invoke();
UiHandlerTest.OK().Invoke();
end;
If you deployed this test and ran it as it is right now, you should see the following test result:
What this means is that there is UI interaction happening within your test that is not being handled. Let's fix that!
- Add the HandlerFunctions attribute to your new test function, between the [Test] attribute and the function declaration, like this:
[Test]
[HandlerFunctions('HandleConfirmDialog')]
procedure TestConfirmHandler()
...
This tells the system that we expect to handle some UI and we will do that using a handler function named HandleConfirmDialog.
- Now, let's create the handler function by adding the following code:
[ConfirmHandler]
procedure HandleConfirmDialog(Question: Text[1024]; var Reply: Boolean)
begin
Reply := true;
end;
We used the ConfirmHandler attribute to specify that this function is for handling a confirmation dialog.
For this test, all we want to do is mimic the user, selecting Yes on the dialog window.
- Now, let's try out our test. Press F5 to build and publish the test app. In your development sandbox, follow these steps:
- Use the
icon to search for Test Tool and click the link to open it.
- Delete any existing entries in the page or create a new test suite.
- Select Process | Get Test Codeunits | Select Test Codeunits and press OK to view the list of all of the testing codeunits.
- Find the My Test entry and select it. Click OK.
- Select Run | All.
- Use the
Now, the test results for our new test should show as a success: