Here is a guide to add live tests for management-plane SDK.
Read Developer Guide. It provides guide on how to build, run tests, and the context of live tests.
Add following test dependencies to POM at sdk/<service>/azure-resourcemanager-<service>/pom.xml,
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.9.1</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.5.2</version> <!-- {x-version-update;com.azure:azure-identity;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-resources</artifactId>
<version>2.15.0</version> <!-- {x-version-update;com.azure.resourcemanager:azure-resourcemanager-resources;dependency} -->
<scope>test</scope>
</dependency>
azure-core-testfor test framework.azure-identityfor authorization.azure-resourcemanager-resourcesfor SDK to manage resource groups.- One might add other required libraries in
testscope.
Note: one only need to add azure-resourcemanager-resources to POM, if the SDK already have mock tests enabled (which is usually the case).
And run
python eng/versioning/update_versions.py --skip-readme
to update the versions in POM.
Add a bicep script at sdk/<service>/test-resources.bicep (example).
No change to the bicep script is required.
- It adds Contributor role of the resource group to the service principal.
- It provides the name of the resource group, as well as credentials for the live tests.
Add live tests (example).
@LiveOnlymake it a live test, without recording and playback.- It uses the
AZURE_RESOURCE_GROUP_NAMEenvironment variable if available. - It uses the
AzurePowerShellCredentialcredential class.
All the environment variables are provided in live tests pipeline.
To verify your tests locally, one need to set these environment variables in local.
For credentials, please refer to guide on authentication.
For the resource group, one can create a resource group, and set its name to AZURE_RESOURCE_GROUP_NAME environment variable.
Make sure your service principal above has Contributor role on the resource group.
And remember to delete it after local tests complete.
Run the tests locally,
mvn test -f sdk/<service>/azure-resourcemanager-<service>/pom.xml -DAZURE_TEST_MODE=LIVE
Add a pipeline configuration for live tests at sdk/<service>/tests.mgmt.yml (example).
After pull request is ready, comment /azp run prepare-pipelines to let the automation create the pipeline from tests.mgmt.yml.
The live tests will be automatically run, before SDK release.
In pull request, comment /azp run java - <service> - mgmt - tests to run it manually.
- Sometimes, the CI could be cancelled due to EngSys problem, please re-run it.
- Resource under test may not have been registered under "Azure SDK Test Resources" subscription. Developer needs to register the resource provider namespace first, then re-run the CI.