官术网_书友最值得收藏!

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;
}
Note that errors are forced to get some useful feedback on the resume message of the test codeunit.

So, we get the following as a result:

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:

主站蜘蛛池模板: 英山县| 云和县| 政和县| 宁河县| 锡林郭勒盟| 南岸区| 琼结县| 台北县| 和静县| 保靖县| 河源市| 道孚县| 茌平县| 宁化县| 陈巴尔虎旗| 玉田县| 云梦县| 许昌县| 彰化县| 安远县| 城固县| 桐乡市| 明星| 津市市| 正安县| 隆化县| 闽清县| 盈江县| 连城县| 大悟县| 大英县| 兴隆县| 呼伦贝尔市| 广宁县| 日土县| 德令哈市| 云和县| 三门县| 湖州市| 石阡县| 铜梁县|