# OnBeforeTestRun (Codeunit) trigger
> Version: _Available or changed with runtime version 1.0._
Runs before a test of a test codeunit is run.
> IMPORTANT
> The ../../properties/devenv-subtype-property must be set to TestRunner in the Codeunit.
## Syntax
```al
trigger OnBeforeTestRun(CodeunitId: Integer; CodeunitName: Text; FunctionName: Text; Permissions: TestPermissions): Ok
begin
    ...
end;
```
### Parameters
CodeunitId
Type: ../../methods-auto/integer/integer-data-type
Specifies the ID of the codeunit to be run.
CodeunitName
Type: ../../methods-auto/text/text-data-type
The name of the test codeunit to be run.
FunctionName
Type: ../../methods-auto/text/text-data-type
Specifies the name of the test to be run.
Permissions
Type: ../../methods-auto/testpermissions/testpermissions-option
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: ../../methods-auto/boolean/boolean-data-type
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 devenv-onrun-codeunit-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.
```al
trigger OnBeforeTestRun(CodeunitId: Integer, CodeunitName: Text, FunctionName: Text, Permissions: TestPermissions): Boolean
var
    Before : DateTime;
begin
    Before := CURRENTDATETIME;
    Exit(true);
end;
```
## Related information
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>
devenv-onaftertestrun-codeunit-trigger
../../properties/devenv-testpermissions-property

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/triggers-auto/codeunit/devenv-onbeforetestrun-codeunit-trigger, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/triggers-auto/codeunit/devenv-onbeforetestrun-codeunit-trigger/
