OnAfterTestRun (Codeunit) trigger
Version: Available or changed with runtime version 1.0.
Runs after a test of a test codeunit has been run.
Important
The Subtype Property must be set to TestRunner in the Codeunit.
Syntax
trigger OnAfterTestRun(CodeunitId: Integer; CodeunitName: Text; FunctionName: Text; Permissions: TestPermissions; Success: Boolean)
begin
...
end;
Parameters
CodeunitId
Type: Integer
Specifies the ID of the codeunit that has run.
CodeunitName
Type: Text
Specifies the name of the test codeunit that has run.
FunctionName
Type: Text
Specifies the name of the test that has 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.
Success
Type: Boolean
True indicates that the test run succeeded; otherwise, false indicates that the test run failed.
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 one at a time in the codeunit. When implemented, the OnAfterTestRun trigger is called after each test has run and after all of the test codeunits have run.
The OnAfterTestRun trigger suppresses the automatic display of the results message after the test codeunit runs.
Note
To return the error message for a failed test run, use the GetLastErrorText Method.
You can use the OnAfterTestRun trigger to perform post-processing, such as logging, or to automate tests by integrating the test runner codeunit with a test management framework.
The Permissions parameter, enables you can control how to handle applied permission sets, if any, after the test is run.
The FunctionName parameter is empty when the OnAfterTestRun trigger is called for the whole test codeunit.
The OnAfterTestRun trigger is run in its own database transaction.
Example
The following OnAfterTestRun trigger code logs test results to a test reporting system. This example requires that you create a record variable named log.
log.Init;
log.UnitId := CodeunitId;
log.Unit := CodeunitName;
log.Func := MethodName;
log.Before := Before;
log.After := CURRENTDATETIME;
if Success then
log.Status := log.Status::Success
else begin
log.Status := log.Status::Failure;
if MethodName <> '' then
log.Message := GETLASTERRORTEXT;
end;
log.Insert(true);
The GetLastErrorText returns the text that was contained in the last error message.
Related information
Get Started with AL
Developing Extensions
SubType Property (Codeunit)
OnBeforeTestRun Trigger