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

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
主站蜘蛛池模板: 临邑县| 宜都市| 屯留县| 孟州市| 柘城县| 襄汾县| 兴业县| 安远县| 同仁县| 嘉鱼县| 收藏| 宁远县| 婺源县| 龙陵县| 乌拉特后旗| 正镶白旗| 许昌县| 新晃| 吉木萨尔县| 中阳县| 大悟县| 名山县| 吴堡县| 肃宁县| 荥阳市| 永春县| 嘉鱼县| 大悟县| 遂昌县| 安徽省| 乌拉特中旗| 壶关县| 潼关县| 阳谷县| 通州区| 奉化市| 军事| 锡林浩特市| 福州市| 乐清市| 苗栗市|