NAVR2 Developer Day (Part 3) - How to use the application testability features

"Hello World", the next report from the NAV 2009 R2 developer day. The third subject is about the testability features in NAV 2009 R2 (and SP1). Again this is just a small overview of the things I noticed during the presentation.

What is testability?

-        Adding features to the product that make it more easy to test, at low cost


-        Functional business logic test from C/AL Code

-        Classic vs. RTC architecture (Test both)

-        Enable negative test

-        Enable scalable test case management and execution

Testability features

-        Test codeunit

-        Test runner codeunit

-        UI Handlers

-        ASSERTERROR statement

You can define a codeunit as a test or test runner with a subtype added to the codeunit properties. Therefore enable “Enable testability options” in Tools -> Options. There is also a Function subtype, you can define normal, test and various handler functions.

Test codeunit

When Test codeunits are run, not the onrun() function is just run but all functions in the codeunit ar run in order.

Note: There was code in de demo: ERROR(WrongInterval.Value);

This is a very strong and important featurer in my opninion. However, I’m wondering if partners are willing to invest the time to create decent test codeunits.

The test environment must be prepared before starting the testcodeunit.

With ASSERTERROR you can define “Negative tests” for tests that are supposed to fail. The code will continue to run after an error occurs in the ASSERTERROR block of code. This can be compared with the “try … catch” in C#. If no error occurs in an ASSERTERROR block, the test will be considered a failure. You can read the error afterwards with the GETLASTERROR function.

To handle confirmation dialogs, you can use a UI handler. It’s a function where you can use a function to handle a dialog. You have to choose a “handler” subtype for this function. You can specify which functions to use as a handler function with the “Handlerfunction” property of the test function you want to run.

TestRunner Codeunit

Used to scale up your tests. You are supposed to use a Testrunner codeunit to run Test codeunit and use it to report your testresults.

Two functions are used “OnBeforeTestRun” and “OnAfterTestRun” that are run before and after each test that is run form the TestRunner codeunit.

An advanced testrunner is available from partnersource.

Application Testablility Features

Currently not targeted

-        Test of UI Logic
-             Code on forms and pages
-             UI interaction (example “CurrFieldNo”)


These are all powerfull features, but the succes will depend on the fact if partners will actually use them. I think it would be wise for Microsoft to provide partners with a full set of standard test codeunits.

Comment List