Skip to main content

Test Toolkit in Business Central(SaaS) - How to setup and execute Custom Test Cases

Introduction:
Test Automation is basically writing code to test and verify whether the application functionality developed works as expected. When you install NAV / Business Central - OnPremise, the installation folder consists of standard Test Toolkit Objects which are to be imported manually if you want to enable Test Automation in your project. But, for Business Central (SaaS) it comes pre-installed.  Let us see how Test Automation is done in Business Central(SaaS) with the help of Test Toolkit and how to set up your own test cases for the customization you've developed for the system.

Books & Reference:
1. Automated Testing in Microsoft Dynamics 365 Business Central (https://tinyurl.com/y3zpy27p)
Pre-requisites:
Microsoft Dynamics Business Central (SaaS)
VS Code(https://code.visualstudio.com/download)
AL Language Extension(https://tinyurl.com/yyvzxwkb)

Demonstration:
1. Checking the installed Test Toolkit in Business Central(SaaS):
When searching for Test Tool in Business Central(SaaS) global search, I didn't find any results.

I checked the Permission Set and its permissions for the User.

Checking the Permissions for the SUPER Permission Set


This only means that either the Object for Test Toolkits are not present or their not accessible directly.
Let us try calling through URL. Append &page=130401 in the URL

Nice!! 😁. Which means that Test Toolkit is not directly accessible through global search.

2. Setting Up Test Toolkit in VS Code:
In the existing app or a new app, you can add a test version parameter in 'app.json' file and download the symbol to get the object reference symbols for Test Toolkit.

3. Creating your own custom Test Toolkit App:
In this, you create your own codeunit to test the cases
SubType = Test which means that this codeunit is to be involved in Test Toolkit. Refer(https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-subtype-codeunit-property)
To get the procedure into Test Toolkit,you have to type [Test] before the procedure just like Event Subscribers


Getting the procedure into the Test Tool


Finally running the function and getting results


Update: 26th August 2020
This functionality is not present in versions 15 and above.

Conclusion:
This is how you can do Test Automation in Business Central. In the upcoming blogs, I will try to get into more details.
Happy Weekend :) Cheers!

Comments

  1. Note: After referring through https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/compliance/apptest-testingyourextension#use-the-right-user-for-your-testing I've understood that SUPER permission is not the right one to run the test toolkit.
    I will blog about this change in the upcoming blogs.

    ReplyDelete
  2. Unfortunatley this is no longer working for the new BC15 and later TestApps and I dont know of any good way to way to accomplish this in the Cloud.

    Maybe someone else knows how to do it for Business Central Sandbox (SaaS)?

    ReplyDelete
  3. Hi Staedter,
    Yes I have noticced that Test Toolkit doesn't download from the SaaS version.

    You can do this through BC 15 Container. Refer Freddy's Blog https://freddysblog.com/2019/07/31/preview-of-dynamics-365-business-central-2019-release-wave-2/

    ReplyDelete
  4. If you want to add the test dependencies you can now do it in the app.json as a dependency, like that:
    "dependencies": [
    {
    "id": "23de40a6-dfe8-4f80-80db-d70f83ce8caf",
    "publisher": "Microsoft",
    "name": "Test Runner",
    "version": "17.0.0.0"
    }
    ]

    Greetings from navdev.eu!

    ReplyDelete
  5. We have an extension with the following event subscriber

    [EventSubscriber(Objecttype::Table, Database::"Sales Line", 'OnAfterDeleteEvent', '', false, false)]

    When we run the extension normally everything works, but when we do the following in a test codeunit

    SalesLine.Delete(true);

    The sales line quantity is 0 in OnAfterDelete Event

    *** This only happens when running a test codeunit ***

    We isolated the issue to this code in the SalesLine.dal (line 3000 and something)

    // In case we have roundings on VAT or Sales Tax, we should update some other line
    if (Type <> Type::" ") and ("Line No." <> 0) and ("Attached to Line No." = 0) and ("Job Contract Entry No." = 0) and
    (Quantity <> 0) and (Amount <> 0) and (Amount <> "Amount Including VAT") and not StatusCheckSuspended
    then begin
    Quantity := 0;
    "Quantity (Base)" := 0;
    "Qty. to Invoice" := 0;
    "Qty. to Invoice (Base)" := 0;
    "Line Discount Amount" := 0;
    "Inv. Discount Amount" := 0;
    "Inv. Disc. Amount to Invoice" := 0;
    UpdateAmounts();
    end;

    We had similar issues with Qty modifications where rec and xRec contained the same values and were able to workaround this with TestPages:

    SalesOrderSubform.OpenEdit();
    SalesOrderSubform.GoToKey(SalesDocTypeEnum::"Order", SalesHeader."No.", SalesLineNo);
    SalesOrderSubform.Quantity.SetValue(10);
    SalesOrderSubform.OK.Invoke();

    Unfortunately, there doesn't seem to be a method in the SalesOrderSubfrom test page to delete a line

    ReplyDelete

Post a Comment

Let me know your comments below. I'll try my best to answer your comment

Popular posts from this blog

Something went wrong. An Error occurred - Error Resolution

Introduction: With the installation of NAV 2018 or BC On-premise, I have observed that when creating New Server Instance and New WebServer Instance, you will get the error 'Something went wrong. An Error occurred '. I referred to the community questions below but didn't find my resolution. Hence, I decided to write this blog. Pre-requisites: Microsoft Dynamics Business Central - On-Premise / NAV 2018 Understanding of Business Central Authentication  Books & References: https://community.dynamics.com/nav/f/microsoft-dynamics-nav-forum/261301/nav-2018-web-client-an-error-has-occurred https://community.dynamics.com/business/f/dynamics-365-business-central-forum/421987/error-something-went-wrong-an-error-has-occurred-azure-ad-tenant Demonstration: 1. Creation of NAVServerInstance: In order to create NAVServerInstance, you can either add the Server Instance through Business Central Administration or Powershell command. Add Instance - Business Central Administration Add Insta

Universal Code Error and Resolution

Introduction: On Friday, May 12th, 2023, the Business Central On-Premise Production Environments started throwing universal code errors as follows. This occurred to every customer on a lower version of BC 19,20 and 21 irrespective of their localization, customization, and license. Pre-requisites:  Understanding of Technical Upgrade in Business Central On-Prem References: BC20 On prem. Universal Code requirement error after installing customer's license. - Dynamics 365 Business Central Forum Community Forum (40) Yammer : Dynamics 365 Business Central Development : View Conversation Root Cause: The certificate that signs Microsoft Base Application was expired. Errors started occurring if you Uninstalled, Installed Extensions, Restart Server Instances or for some even out of random started popping out. We first thought could be a license issue as we had fixed that before but this did not solve the issue. Resolution: Microsoft identified the issue and posted the following update The mi

How to resolve 'Edit in Excel' issues

  Introduction: As you know that D365 BC offers Edit in Excel functionality. But manipulating or customizing such a  standard functionality is difficult as there is not much control available. Hence, solving issues is also a difficult task. I will be resolving the issue for this specific issue, however, the debugging steps are similar. Pre- requisites : ODATA V4 Connectivity tool for Webservices Microsoft Dynamics 365 Business Central Books & References: https://community.dynamics.com/business/f/dynamics-365-business-central-forum/448226/issue-with-excel-add-in/ Demonstration: The way Edit in Excel works is that for a given page a Webservice is created adding PageID and Page Name. Hence, there are some Webservice connectivity checks in place to validate. 1. Edit in Excel Custom Action on the page: If you are adding Edit in Excel Action on the page, please ensure that you are providing appropriate PageName and Filter criteria as Webservice is using these parameters Refer Editworkshe