- Automated Testing in Microsoft Dynamics 365 Business Central
- Luc van Vugt
- 405字
- 2021-06-24 14:56:51
Pillar 5 – Test pages
Goal: Understand what test pages are and learn how to apply them when testing the UI.
The initial trigger for adding the testability framework to the platform was to get away from testing the business logic through the UI. The testability framework enabled headless, and thus faster, testing of the business logic. And this is how the testability framework was implemented in NAV 2009 SP1. Pure headless testing. It included everything of the four pillars discussed so far, even though test isolation was implemented in a different way than it is today. It was previously not possible to test the UI.
Moving ahead, it became clear that sole headless tests excluded too much. How could we test business logic that typically resides on pages? For example, consider a product configurator in which options are displayed or hidden depending on values entered by the user. So, with NAV 2013, Microsoft added the fifth pillar to the testability framework: test pages.
A test page is a logical representation of a page and is strictly handled in memory displaying no UI. To define a test page, you need to declare a variable of the TestPage type:
PaymentTerms: TestPage "Payment Terms";
A TestPage variable can be based on any page existing in the solution.
A test page allows you to mimic a user carrying out the following actions:
- Accessing the page
- Accessing its sub parts
- Reading and changing data on it
- Performing actions on it
You can achieve this by using the various methods that belong to the test page object. Let's build a small codeunit in which we use a couple of them:
codeunit 60003 MyFourthTestCodeunit
{
Subtype = Test;
[Test]
procedure MyFirstTestPageTestFunction()
var
PaymentTerms: TestPage "Payment Terms";
begin
PaymentTerms.OpenView();
PaymentTerms.Last();
PaymentTerms.Code.AssertEquals('LUC');
PaymentTerms.Close();
end;
[Test]
procedure MySecondTestPageTestFunction()
var
PaymentTerms: TestPage "Payment Terms";
begin
PaymentTerms.OpenNew();
PaymentTerms.Code.SetValue('LUC');
PaymentTerms."Discount %".SetValue('56');
PaymentTerms.Description.SetValue(
PaymentTerms.Code.Value()
);
ERROR('Code: %1 \ Discount %: %2 \Description: %3',
PaymentTerms.Code.Value(),
PaymentTerms."Discount %".Value(),
PaymentTerms.Description.Value()
);
PaymentTerms.Close();
end;
}
So, we get the following as a result:

For a complete listing of all test page methods, you can access the following URLs:
TestPage: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/testpage/testpage-data-type
TestField: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/testfield/testfield-data-type
TestAction: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/testaction/testaction-data-type
If you are running Microsoft 365 Business Central on-premises and you want to run tests using test pages, be sure that you have the Page Testability module installed:

- 非凡韌性(清華終身學習系列出版物)
- 理想的團隊成員:識別和培養(yǎng)團隊協(xié)作者的三項品德(經(jīng)典版)
- 小公司營銷術(shù)
- 國資航母:國有資本投資公司改革探索與實踐
- 識人·用人·帶隊伍:九種個性與團隊建設(shè)
- 快魚戰(zhàn)略
- 游戲,讓學習高效
- CIO大視野:“互聯(lián)網(wǎng)+”時代的信息化實戰(zhàn)分享
- 落實力就是戰(zhàn)斗力
- 國有企業(yè)監(jiān)事會履職實錄
- 阿里巴巴管理法
- 公司增長的本質(zhì)
- 核心圈法則
- 中國上市公司年報文本信息披露特征、生成機制與經(jīng)濟后果:基于同伴效應的研究
- 藍血16杰:BAT幫創(chuàng)業(yè)的故事