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.
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
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
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!
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!
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.
ReplyDeleteI will blog about this change in the upcoming blogs.
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.
ReplyDeleteMaybe someone else knows how to do it for Business Central Sandbox (SaaS)?
Hi Staedter,
ReplyDeleteYes 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/
If you want to add the test dependencies you can now do it in the app.json as a dependency, like that:
ReplyDelete"dependencies": [
{
"id": "23de40a6-dfe8-4f80-80db-d70f83ce8caf",
"publisher": "Microsoft",
"name": "Test Runner",
"version": "17.0.0.0"
}
]
Greetings from navdev.eu!
We have an extension with the following event subscriber
ReplyDelete[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