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

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
主站蜘蛛池模板: 会东县| 吉林市| 安丘市| 尼玛县| 富锦市| 巨野县| 淮北市| 井冈山市| 建湖县| 禄丰县| 喜德县| 穆棱市| 旬阳县| 汝阳县| 图们市| 天台县| 扶风县| 昭平县| 福清市| 陵川县| 兴文县| 达拉特旗| 临西县| 长顺县| 赤峰市| 增城市| 两当县| 桂阳县| 金川县| 安宁市| 榆中县| 搜索| 德化县| 全南县| 界首市| 吴川市| 台江县| 天祝| 鄂尔多斯市| 通辽市| 霍城县|