- Automated Testing in Microsoft Dynamics 365 Business Central
- Luc van Vugt
- 235字
- 2021-06-24 14:56:50
Test runner
Like any other codeunit, a test runner codeunit can have a OnRun trigger and normal user-defined functions, but, in addition to that, you can also add two test runner-specific triggers called OnBeforeTestRun and OnAfterTestRun. When test codeunits are called from the OnRun trigger of a test runner, OnBeforeTestRun and OnAfterTestRun will be triggered by the system as follows:
- OnBeforeTestRun: This is triggered before the test codeunit is called, the test codeunit OnRun trigger is executed, and each of its test functions is run
- OnAfterTestRun: This is triggered after each test function has run and the test codeunit finishes
Use the OnBeforeTestRun trigger to perform a test run pre-initialization and control the execution of a whole test codeunit and individual test functions. The latter can be achieved by using the Boolean return value of the OnBeforeTestRun trigger. Returning TRUE, the test codeunit or test function runs. Returning FALSE, it is skipped.
Use the OnAfterTestRun trigger to perform post-processing, such as logging the result of each test. When the OnAfterTestRun trigger is run, the standard result message box, as we have seen so far, is not shown.
Both OnBeforeTestRun and OnAfterTestRun are run in their own database transaction. This means that changes made to the database with each of these triggers are committed once their execution finishes.
OnBeforeTestRun : https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/triggers/devenv-trigger-onbeforetestrun
OnAfterTestRun: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/triggers/devenv-trigger-onaftertestrun