편집

다음을 통해 공유


OnBeforeTestRun (Codeunit) trigger

Version: Available or changed with runtime version 1.0.

Runs before a test of a test codeunit is run.

Important

The Subtype Property must be set to TestRunner in the Codeunit.

Syntax

trigger OnBeforeTestRun(CodeunitId: Integer; CodeunitName: Text; FunctionName: Text; Permissions: TestPermissions): Ok
begin
    ...
end;

Parameters

CodeunitId
 Type: Integer
Specifies the ID of the codeunit to be run.

CodeunitName
 Type: Text
The name of the test codeunit to be run.

FunctionName
 Type: Text
Specifies the name of the test to be run.

Permissions
 Type: TestPermissions
Specifies the permission set level to use on the test run. The value is retrieved from the TestPermissions property of the test codeunit or test that is run. The parameter accepts the following values:

  • Disabled
  • Restrictive
  • NonRestrictive
  • InheritFromTestCodunit - Specifies that a test the uses the TestPermissions property setting of the test codeunit to which it belongs.

Return Value

Ok
 Type: Boolean
true if the test was run, otherwise, false. The default value is true.

Remarks

Note

This trigger is optional and not available on a test runner codeunit by default. To implement this trigger, you must manually add it.

A test runner codeunit manages the execution of test codeunits that are run from its OnRun trigger. When a test codeunit runs, it executes each test in the codeunit, one at a time. The OnBeforeTestRun trigger is called before the test codeunit, the OnRun , and each test .

You can use the OnBeforeTestRun triggers to perform preprocessing, such as general initialization and logging, or to automate tests by integrating the test runner codeunit with a test management framework.

By using the Permissions parameter, you can add code to control which permission sets, if any, to test.

The FunctionName parameter is empty when the OnBeforeTestRun trigger is called for the entire test codeunit.

The OnBeforeTestRun trigger is run in its own database transaction.

Example

The following OnBeforeTestRun trigger code initializes a logging variable and returns true to indicate that the test should execute.

trigger OnBeforeTestRun(CodeunitId: Integer, CodeunitName: Text, FunctionName: Text, Permissions: TestPermissions): Boolean
var
    Before : DateTime;
begin
    Before := CURRENTDATETIME;  
    Exit(true);  
end;

Get Started with AL
Developing Extensions
OnAfterTestRun Trigger
TestPermissions Property