How to: Create Test Codeunits and Test Functions
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 create test functions within the test codeunits.
When you create a new function in a test codeunit, the FunctionType property is set to Test by default.
To create a test codeunit and test functions
On the Tools menu, click Options.
In the Options window, in the Show C/AL Testability properties field, enter Yes, and then click OK.
In the Classic client, on the Tools menu, click Object Designer.
In Object Designer, click Codeunit, and then click New.
On the View menu, click Properties.
In the Properties window, in the Subtype field, select Test to specify that this is a test codeunit.
On the View menu, click C/AL Globals.
In the C/AL Globals window, on the Functions tab, enter the names of the test functions in this test codeunit.
For each test function, select the function, click View, click Properties, and then verify that the FunctionType property is set to Test.
If any test functions need UI handlers, then enter the names of the handler functions in the C/AL Globals window. For more information, see How to: Create Handler Functions.
In the C/AL Editor, enter code for each test function and handler function that you defined. You can also enter code in the OnRun function. The OnRun function runs when you execute the codeunit and before the test functions run.
Test functions must not have parameters or return values.
On the File menu, click Save. In the Save window, verify that the Compiled check box is selected, and then click OK to save and compile the test codeunit.