You can create test codeunits, test functions, 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 do not require user interaction when they are running. To do this, you create special handler functions.
You can use the following handler functions:
Note If you create a ReportHandler function, then that function replaces all code for running the report, including the request page, and a RequestPageHandler is not called. Only create a RequestPageHandler if you are not using a ReportHandler.
The FilterPageHandler tests the UI that is generated by a FILTERPAGEBUILDER data type. For more information about the FILTERPAGEBUILDER data type, see Creating Filter Pages for Filtering Tables.
Before you begin, you must create a test codeunit and test function. For more information, see How to: Create Test Codeunits and Test Functions.
To create a handler function
In the development environment, on the Tools menu, choose Object Designer.
In Object Designer, choose Codeunit, select your test codeunit, and then choose Design.
On the View menu, choose C/AL Globals.
In the C/AL Globals window, on the Functions tab, enter the name of the new handler function.
On the View menu, choose Properties.
In the Properties window, in the FunctionType property, select the type of handler from the drop-down list.
In the C/AL Globals window, on the Functions tab, choose Locals to specify the signature of the handler functions. The following table describes the signature that is required for each type of handler function.
<Function name>(<Msg> : Text)
<Function name>(<Question> : Text; VAR <Reply> : Boolean)
<Function name>(<Options : Test; VAR <Choice> : Integer; <Instruction> : Text)
<Function name>(VAR <variable name> : Page <page id>)
<Function name>(VAR <variable name> : TestPage <testpage id>)
<Function name>(VAR <variable name> : Page <page id>; VAR <Response> : Action)
<Function name>(VAR <variable name> : Page <testpage id>)
<Function name>(VAR <report name> : Report <report id>)
<Function name>(VAR <TestRequestPage > : TestRequestPage)
<Function name>(VAR <RecRef1> : RecordRef)[, VAR <RecRef2> : RecordRef]
Note You must a VAR parameter for each record on the FilterPageBuilder object. For more informatiion about Filter
<Function name>(<Hyperlink> : Text)
The parameters of the functions that are being handled are passed as parameters to the handler functions. For example, when MESSAGE is called in a test function, the parameter of the MESSAGE function is passed as the parameter of the MessageHandler function. For page and report handlers, the page, report, or request page is passed as the parameter of the PageHandler, ModalPageHandler, ReportHandler, or RequestPageHandler.
Parameters that are specified as VAR are passed by reference to the handler function. The value of the parameter can be changed by the handler function.
For example, to specify the signature for a ConfirmHandler function, do the following:
In the C/AL Locals window, on the Parameters tab, enter a name for the <Question> parameter. In the DataType field, select Text. In the Length field, enter 1024. Verify that the Subtype field is blank.
Enter a name for the <Reply> parameter. In the Var field, select the check box. In the DataType field, select Boolean. Verify that the Subtype and Length fields are blank.
In the code of the ConfirmHandler function, set the reply that you want to simulate by setting the value of the Reply parameter.
- In the C/AL Locals window, on the Parameters tab, enter a name for the <Question> parameter. In the DataType field, select Text. In the Length field, enter 1024. Verify that the Subtype field is blank.
In the C/AL Globals window, select the test function that requires a handler function. For example, a test function that requires a handler function calls some application code, which then calls the CONFIRM function.
On the View menu, choose Properties.
In the Properties window for the test function, in the HandlerFunctions property, enter the name of the handler function that this test function will use instead of the UI. For example, if the code tested by this test function calls the CONFIRM function, then enter the name of your ConfirmHandler function. To specify more than one handler function, separate the handler function names with a comma.
Note Every handler function that you enter in the HandlerFunctions property of a test function must be called at least one time in the test function. If you run a test function that has a handler function listed that is not called, then the test fails.
In the C/AL Editor, enter code for the handler functions that you defined. The code should simulate in the code that is being tested that the UI was actually raised and some values entered or some actions were taken. For example, the code could verify that the expected text is presented. The code should exit with the same state with which the UI would exit.
On the File menu, choose Save.
In the Save window, verify that the Compiled check box is selected, and then choose the OK button to save and compile the test codeunit.