Execute unit tests in Azure Pipelines
An Azure Pipeline build task is available that lets users execute unit tests on connected cloud runtime environments using a continuous integration/continuous delivery (CI/CD) pipeline. The "Execute Unit Tests in Unified Environment" task is included in the Dynamics 365 Finance and Operations Tools extension.
More information: Continuous integration and deployment, Build automation that uses Microsoft-hosted agents and Azure Pipelines
Prerequisites
To be successful in using this unit test capability, you must have:
- Working knowledge of building and deploying X++ code using Azure Pipelines. For more information, see the linked articles provided in the See also section.
- Understanding of X++ unit test execution and general development.
- Availability of this unit test execution capability in your organization.
Add a unit test task to a pipeline
Adding the ability to execute unit tests requires a build pipeline that can build and deploy a solution to the unified developer experience environment. The tests are obtained from the test models included in the repository, based on the assembly output of the Build Solution pipeline task. The same tests must be pre-deployed on the unified developer experience environment for the test execution to be possible. This deployment can be accomplished in the same run of the pipeline or separately.
The deployment task is only required if there are any changes of the test cases that aren't deployed on the environment. However, the build task is necessary to identify which tests must be run. This unit test task must be included after the optional build and deploy tasks.
In this next figure, the "Execute Unit Tests in Unified Environment" task is included in en example build pipeline.
The output logs of the task contains information of each test executed and its output. The task fails if any of the tests that are run fail.
Creating the unit test task
Important
- A new version (1.*) of the task has been released. See Update: Version 1 for more information.
In this next image is an example unit test being defined. A description of each form field follows.
Form field | Description |
---|---|
Display name | The name of the test execution task. |
Service connection | Service connection to the unified developer experience environment on which the deployment has been made. |
Package Platform Version Package Application Version |
Versions of the deployed package and connected environment. |
Platform Package Path | The location of the Microsoft.Dynamics.AX.Platform.DevALM.BuildXpp NuGet package installed on the agent. |
X++ Tools Path | The location of the Microsoft.Dynamics.AX.Platform.CompilerPackage NuGet package installed on the agent. |
Location of the X++ modules to test | The storage location where the build task produced the assemblies of the models included. This value is often set to $(Build.BinariesDirectory). |
Search patterns for the X++ modules to test | Include the pattern for the modules that the tests must be run for. Provide a name matching pattern for X++ package (module) names inside the path that is specified in the location of the X++ modules to test option. You can also specify a list of names instead of search patterns, or exclusion filters. More information: File matching patterns reference. |
Update: Version 1
A new version (1.*) of the Execute Unit Tests in Unified Environments task is available. This version replaces the Service Connection authentication field. Now you can use multiple authentication mechanisms, like username/password and appId/client Secret to execute the test requests.
You can use the existing Power Platform Set Connection Variables task to generate the connection string in the same pipeline before using the unit test execution task. Learn more about the details for this task and about connection types. You can retrieve the connection string and use it in subsequent tasks by creating a reference name in the Output Variables section for classic pipelines.
The following image shows how to use the task to generate an output variable named op
that is referenced in the subsequent unit test execution task:
You can also use this in a YAML pipeline:
Sample Power Platform Set Connection Variables task – Use either of the connection types and replace the URL and the service connection name, as shown in Power Platform Set Connection Variables. Use the name
field to specify the output variable.
task: microsoft-IsvExpTools.PowerPlatform-BuildTools.set-connection-variables.PowerPlatformSetConnectionVariables@2
displayName: 'Power Platform Set Connection Variables '
inputs:
authenticationType: PowerPlatformSPN
PowerPlatformSPN: <Service Connection>
Environment: '<Power platform environment URL>'
name: 'op'
The following screenshot shows the same reference name used in a unit test task:
Known Issues
The Execute Unit Tests in Unified Environment task is stuck/times out after message: “Starting submit of test request:”
Solution: This could occur if the Connection string provided by the user is of type Username/Password and has MFA enabled. Only Service Principal/Client Secret authentication or Username/Password without MFA authentication are supported.
See also
Unit testing
Continuous integration and deployment
Build automation that uses Microsoft-hosted agents and Azure Pipelines
Unit Test Framework