The content in this topic only applies to Microsoft Dynamics NAV 2009 SP1. For Microsoft Dynamics NAV 2009 content, see Developer and IT Pro Help for Microsoft Dynamics NAV 2009.

In Microsoft Dynamics NAV 2009 SP1, you can create test codeunits and test functions 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 running. To do this, you create special handler functions.

The following handler functions are available:

Before you begin, you must do the following:

For more information, see How to: Create Test Codeunits and Test Functions.

To create a handler function

  1. In the Classic client, on the Tools menu, click Object Designer.

  2. In Object Designer, click Codeunit, select your test codeunit, and then click Design.

  3. On the View menu, click C/AL Globals.

  4. In the C/AL Globals window, on the Functions tab, enter the name of the new handler function.

  5. On the View menu, click Properties.

  6. In the Properties window, in the FunctionType property, select the type of handler from the drop-down list.

  7. In the C/AL Globals window, on the Functions tab, click Locals to specify the signature of the handler functions. The following table describes the signature that is required for each type of handler function.

    FunctionType Signature


    <Function name>(<Msg> : Text[1024])


    <Function name>(<Question> : Text[1024]; VAR <Reply> : Boolean)


    <Function name>(<Options : Test[1024]; VAR <Choice> : Integer; <Instruction> : Text[1024])


    <Function name>(VAR <form name> : Form <form id>)


    <Function name>(VAR <form name> : Form <form id>; VAR <Response> : Action)


    <Function name>(VAR <report name> : Report <report id>)

    The parameters of the functions that are being handled are passed as parameters to the handler functions. 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:

    1. 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.

    2. 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.

    3. In the code of the ConfirmHandler function, set the reply that you want to simulate by setting the value of the Reply parameter.

  8. 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 is one that calls some application code, which then calls the CONFIRM function.

  9. On the View menu, click Properties.

  10. 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, enter the name of your ConfirmHandler function. To specify more than one handler function, separate the handler function names by a comma.


    Every handler function that you enter in the HandlerFunctions property of a test function must be called at least once in the test function. If you execute a test function that has a handler function listed that is not called, then the test fails.

  11. In the C/AL Editor, enter code for the handler functions that you defined. The code should simulate to 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.

  12. On the File menu, click Save.

  13. In the Save window, verify that the Compiled check box is selected, and then click OK to save and compile the test codeunit.

See Also