For a long while, ever since NAV 2016, the Test Tool has been part of the application, which is in a way is somewhat strange as a Test Tool is typically something you don’t want to be present in a production environment. Among other – more – important reasons, Microsoft introduced the AL Test Tool in the time of BC15, which resides in it’s own extension called Test Runner. This does not reside in a CRONUS database, and thus typically needs to be installed before you can use it. To discriminate better between the two test tools I will refer to the first as CAL Test Tool – which happens to be the internal naming anyway – and the AL Test Tool.
Both test tools allow you to manage and run the automated tests that reside in the database, and collect their results, be they test codeunits that belong to the standard application or that are part of your code, C/AL or AL based extensions. In the 1st edition of my book Automated Testing in Microsoft Dynamics 365 Business Central, written for BC14 and older versions, the AL Test Tool did not yet exist and in the various hands-on test example I heavily made use of the CAL Test Tool. The 2nd edition of the book, to be released in October and based on BC19, will make use of the AL Test Tool as the CAL Test Tool will be soon deprecated. So, no mentioning of the latter test tool anymore in the 2nd edition.
For those, however, still wanting to use the CAL Test Tool, I will share in this blog post the description of this test tool from the 1st edition of the book.
You can easily access the test tool by searching for Test Tool in either the Windows or the Web client. When in a clean database, or at least a database or company where the Test Tool has not been used yet, this is how the Test Tool appears. A suite called DEFAULT with no records in it appears, as seen as follows:
To populate the suite take the following steps:
- Select the Get Test Codeunits
- On the dialog that opens, you have the following two options:
- Select Test Codeunits: This will open a list page showing all test codeunits that are present in the database from which you can select specific test codeunits; once you have selected and clicked OK, these codeunits will be added to the suite
- All Test Codeunits: This will add all test codeunits that exist in the database to the test suite
Let’s select the first option, Select Test Codeunits. This will open the CAL Test Get Codeunits page showing all test codeunits. Unsurprisingly, in the context of the book, it shows the four test codeunits were created in Chapter 2, The Testability Framework, followed by the long list of over 700 standard test codeunits, as these were also added to the installation:
Note: as mentioned the 60000 range objects were created as part of Chapter 2 of the 1st edition. The code for these test codeunit can be found on the GitHub repo, folder Chapter 2, that goes with that edition: Automated Testing in Microsoft Dynamics 365 Business Central, published by Packt (github.com).
- Select the four test codeunits 60000 through 60003 and click OK.
The suite now shows for each test Codeunit a line with LINE TYPE = Codeunit and, linked to this line and indented, all its test functions (LINE TYPE = Function) as shown in the following screenshot:
- To run the tests, select the Run
- On the following dialog that opens, with options Active Codeunit and All, select All and press OK. Now all four test codeunits will be run and each test will yield a result Success or Failure:
Had we selected the option Active Codeunit only, the selected codeunit would have been executed.
For each failure, the First Error field will display the error that caused the failure. As you can see, First Error is a FlowField. If you drill down into it, the CAL Test Result window opens. This displays the whole test run history for a specific test. Note that the message dialog in
MyFirstTestCodeunit yields an
Unhandled UI error.
Running the test by selecting Run will call the standard test runner codeunit
CAL Test Runner (130400) and will make sure that the following happen:
- Tests run from the Test Tool will be run in isolation
- The results of each test function will be logged
The CAL Test Tool also holds a powerful feature that can be of great help in picking out relevant test codeunits for the code update you are working on. It is called Test Coverage Map (TCM). It combines the result of the code coverage tool that also resides in Business Central and the test tool. Having TCM turned on, it adds two extra options to the Get Test Codeunits feature already demoed in Chapter 3, The Test Tool and Standard Tests. There, we explained that Get Test Codeunits offers the following two options to let you populate your test suite:
- Select Test Codeunits
- All Test Codeunits
With TCM, two more options are added.
Choosing the third option, Get Test Codeunits based on Modified Objects, will select those test codeunits that will hit the application objects you are working on. The fourth option, Get Test Codeunits based on Selected Objects, let’s you select from a list those application objects you want to run tests against.
At this very moment, the Get Test Codeunits based on Modified Objects option only takes into account the application objects that reside in standard, that is, in C/SIDE. Unfortunately, it does not yet consider objects that reside in extensions.
Note: Probably for the latter reason TCM is only part of the CAL Test Tool and not of the AL Test Tool.
The fourth option, Get Test Codeunits based on Selected Objects, nevertheless includes all application objects.
To be able to use TCM, you need to turn it on. To do this, check mark the Update Test Coverage Map field on a test suite. If this has not been turned on, on any test suite, TCM will not have data to allow you to choose Get Test Codeunits based on Modified Objects and Get Test Codeunits based on Selected Objects options as described previously.
Note: For TCM to have the data available to do its job, the activated test suite should be run first.
In this overview of the CAL Test Tool, we used the following features:
- Get test codeunits
- Creating multiple test suites
- Test Coverage Map
It will be published around the released of Dynamics 365 Business Central 2021 wave 2. You can read about its project content here: Automated Testing in Microsoft Dynamics 365 Business Central: Efficiently automate test cases for faster development cycles with less time needed for manual testing, 2nd Edition.