Test Isolation in the Application Test Automation Suite

In Microsoft Dynamics NAV 2016, the test automation suite helps you test new business logic. Test isolation is one of the most important benefits introduced by the Test Automation suite. It specifies how to roll back changes to the database after you have made tests in the test runner codeunit. You can specify that the system should roll back all changes to the database after each test codeunit, or after each test function has been executed. The following provides some notes and important points to be aware of.

AutoIncrement Property

If you run a test that inserts records into a table where the field from the primary key has activated the Autoincrement property, be aware that the records will be rolled back. However, for new records, the system will assign values, taking into consideration the records created during the test execution.


In the Reservation Entry table (table 337), the Entry No. field has the AutoIncrement property set to Yes.

  1. Run the following command in SQL Management Studio to check the current identity value for the table:
    DBCC CHECKIDENT ([CRONUS International Ltd_$Reservation Entry]);
  2. The query execution results in the following message:
    “Checking identity information: current identity value ‘1’, current column value ‘1’.”
  3. Open the Test Tool window and run any test that inserts records into the Reservation Entry table (this is a broadly used table, not only for reservations but also for order tracking, planning, and item tracking).
  4. After the test execution, run the DBCC CHECKIDENT command again. Notice that the current identity value has changed:
    “Checking identity information: current identity value ’78’, current column value ‘1’.”

Can you guess the value in the Entry No field for the next record in the Reservation Entry table?

Other examples of this can be found as part of the standard transaction model and can be reproduced without tests, however, with tests we encounter this situation more often.

Single-instance Codeunits

If you set some values to be single-instance codeunits, you should be aware that they will not be rolled back.


In codeunit 1504, Workflow Blocking Management, the SingleInstance property is set to Yes.

  1. Create a test codeunit with the TestSingleInstanseIsolation test function.
  2. Add the following local variable:
    WorkflowBlockingManagement: Codeunit Workflow Blocking Management
  3. Add the following code to your test:
  1. Run Test Tool and execute the test several times. Notice that every execution gives a different result.

Although there is a limited amount of single-instance codeunits in the application, there are two test libraries that are widely used in tests: Random library and Variable Storage library. If you use these libraries in your test, remember to add the following lines into the Initialize function:


Work Date

If you set the work date during test execution, it will not be changed back once the execution is finished.


  1. Create a test codeunit with the TestWorkDateIsolation test function.
  2. Add the following C/AL code:
  1. Run the Test Tool and execute the tests. Note that now the system has a new workdate.


Remember that you cannot expect the TestIsolation property to roll back files. Test isolation is only used for data in the database, so you should manage your files for yourself.

For more information about the application test automation suite, aka.ms/navgetready and Application Test Automation.