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

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:

主站蜘蛛池模板: 阿瓦提县| 永康市| 百色市| 井陉县| 张家口市| 津南区| 武邑县| 河间市| 民勤县| 潼南县| 昌邑市| 务川| 仪陇县| 泾阳县| 德州市| 承德县| 千阳县| 珠海市| 凌海市| 泸定县| 深州市| 大悟县| 峨眉山市| 彰武县| 平远县| 楚雄市| 沙田区| 全南县| 屯留县| 淅川县| 夹江县| 肃北| 汕头市| 金川县| 庄浪县| 黑龙江省| 临朐县| 鄂州市| 兴宁市| 罗源县| 江西省|