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

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:

主站蜘蛛池模板: 安义县| 高密市| 丰城市| 许昌市| 固原市| 吉首市| 射阳县| 精河县| 金阳县| 成武县| 旅游| 仁化县| 新宾| 常山县| 宜兰市| 乐清市| 舟曲县| 突泉县| 北票市| 永仁县| 玛纳斯县| 绥芬河市| 乐昌市| 柘荣县| 丹江口市| 百色市| 邛崃市| 四会市| 南丹县| 慈利县| 漯河市| 讷河市| 新巴尔虎右旗| 海口市| 眉山市| 汉川市| 新昌县| 达孜县| 栾川县| 镇沅| 沂水县|