Run the standard tests

Completed

Once the Test Tool is installed, you can run the standard tests (if they were installed). Search for Test Tool using Tell Me.

Screenshot of the search for Test Tool using Tell Me.

Depending on the version, you'll see two entries listed: Test Tool and AL Test Tool. The Test Tool is the older C/AL Test Tool, which you can still use, but it's recommended to use the new AL Test Tool, because the C/AL Test Tool will be removed sometime in the future.

Click the AL Test Tool link to open the Test Tool page where you can select and run tests. The first time you open the Test Tool page, it will appear empty. Tests are grouped in a Test Suite. The standard Test Suite is called DEFAULT, which has no records initially. Create your own Test Suites to group different tests together. Grouping is useful in your DevOps build pipeline because you can run the test using the command line and specify the Test Suite to use.

To get some tests in a suite, click the Get Test Codeunits action and select the Tests you want to add to the Test Suite. You can also use the Get Test Codeunits by Range action to provide a range of codeunits object IDs. Codeunits you created yourself and published using extensions will also appear in this list.

After selecting one or both options, you'll get a list with the selected codeunits and all Test Functions within that codeunit. To run the tests, click the Run Tests action. You can select to run all functions, or only from the selected codeunit.

Screenshot of the selected codeunits and Test Functionss with Run Tests action.

After running the tests, you'll get an overview with all tests that succeeded, but you'll also get a list of all failed tests. The Error Message column displays errors for any failed tests.

Screenshot of the overview of all tests with error messages for any that failed.

The standard Test Runner Codeunit will be used, which will run the Tests in isolation and log the results of the test functions.

Run tests via PowerShell

You can also run the tests via PowerShell, which you need in your build pipelines. In the NavContainerHelper, you can find the Cmdlet Get-TestsFromBCContainer and Run-TestsInBCContainer.

With the Get-TestsFromBCContainer, you get a list of all the available tests. Optionally you can specify the -testSuite option to set the required Test Suite. By default, the DEFAULT Test Suite is used.

Get-TestsFromBCContainer -containerName MyDevContainer -credential $credential

To specify the credentials if you are using NavUserPassword as your authentication type, you can create a PowerShell variable:

$credential = New-Object pscredential 'admin', (ConvertTo-SecureString -String 'P@ssword1' -AsPlainText -Force)

After that you can run the tests using the Run-TestsInBCContainer, which will give you a list of the failed or succeeded functions.

Run-TestsInBCContainer -containerName MyDevContainer -credential $credential -detailed

The -detailed option only shows extra information on the host, and will print information about every test, whether they succeeded or failed. If you omit this option, only failing tests will be displayed in the output.

You can optionally set options on the Cmdlet:

  • testSuite: you will always filter the tests to a specific test suite. By default, you filter to the DEFAULT test suite, which means that the remaining parameters will only filter tests in that test suite.

  • testGroup: name pattern of the test group to run -- or * to run all test groups in the test suite.

  • testCodeunit: name or ID pattern of test codeunits to run -- or * to run all test codeunits in the test group / suite.

  • testFunction: name pattern of the test functions to run -- or * to run all test functions in the test codeunit / group / suite.

The Run-TestsInBCContainer can also create an XUnit compatible output by specifying the -XUnitResultFileName option. This should be set to a file path which is shared with the container. XUnit is one of the formats that Azure DevOps supports to display information about the tests in the build pipeline. More information on the XUnit standard can be found in xUnit.net v2 XML Format.

To find out more on how to get the maximum out of the available functions, there is a blog post on the different options with the Run-TestsInBCContainer Cmdlet.

You can find the blog post here: Running Tests In Containers.