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

Test functions

A Test function is defined by the FunctionType tag:

[Test]
procedure MyFirstTestFunction()
begin

end;

This makes it different from a standard function:

  • It has to be global
  • It cannot have arguments
  • It yields a result, which is either SUCCESS or FAILURE

When SUCCESS is returned by a test, it means that no error occurred in the execution of the test. Consequently, when FAILURE is returned, the test execution did throw an error. This error could be due to various reasons, such as the following:

  • Code execution hitting a TestField, FieldError, or Error call
  • Data modifications not being fulfilled because of version conflicts, primary key conflicts, or locks

The latter, a Test function returning FAILURE, brings us to another typicality of a test codeunit—when a test fails, the execution of a test codeunit doesn't halt. It continues to execute the next Test function.

Let's build two simple tests, one returning SUCCESS and the other FAILURE:

codeunit 60000 MyFirstTestCodeunit
{
Subtype = Test;

[Test]
procedure MyFirstTestFunction()
begin
Message('MyFirstTestFunction');
end;

[Test]
procedure MySecondTestFunction()
begin
Error('MySecondTestFunction');
end;
}

Now you can run them.

As test functions are executed from top to bottom, the message thrown by MyFirstTestFunction will show the following screenshot first:

After that, the following message is shown, being a resume message of the execution of the whole test codeunit:

Note that the error did not appear like a message box, but is collected by the platform and recorded as part of the result of the failing test.

To be able to run the test codeunit, I built a simple page, MyTestsExecutor, with an action calling MyFirstTestCodeunit:

page 60000 MyTestsExecutor
{
PageType = Card;
ApplicationArea = All;
UsageCategory = Tasks;
Caption = 'My Test Executor';

actions
{
area(Processing)
{
action(MyFirstTestCodeunit)
{
Caption = 'My First Test Codeunit';
ToolTip = 'Executes My First Test Codeunit';
ApplicationArea = All;
Image = ExecuteBatch;
RunObject = codeunit MyFirstTestCodeunit;
}
}
}
}

If you are following me using the code on GitHub and have a hard time opening the MyTestsExecutor page, use any of the following options:

  • Set startupObjectType to Page and startupObjectId to 60000 in the launch.json
  • Add ?page=6000 to the web client URL in the address bar of your browser: http://localhost:8080/BC130/?page=6000
  • Use Alt + Q, Tell me what you want, in the web client and search for My Test Executor
  • Launch the page directly from the VS Code, making use of a VS Code AL extension such as CRS AL Language Extension
主站蜘蛛池模板: 雅江县| 蒙山县| 沙田区| 隆化县| 京山县| 竹北市| 顺昌县| 色达县| 阳原县| 治多县| 沭阳县| 都江堰市| 明光市| 上思县| 吴忠市| 中宁县| 高台县| 宕昌县| 高台县| 嘉黎县| 南华县| 汉中市| 旬邑县| 郸城县| 宝清县| 噶尔县| 高陵县| 米林县| 剑阁县| 梧州市| 隆回县| 肇州县| 五峰| 盐边县| 三穗县| 陵川县| 平乡县| 卢氏县| 阿拉善盟| 岫岩| 克拉玛依市|