First, ensure that you have accesses to
- Azure DevOps Access
- Azure DevOps CLI or REST API
- Tools Installation (Azure DevOps CLI installed)
Steps to Export Test Suites and Test Plans
- Export Test Plans and Test Suites using Azure DevOps REST API:
- You will need to call the REST API to get the test plans and test suites. You can use the
GET
method for the following endpoints: - Test Plans:
GET https://dev.azure.com/{organization}/{project}/_apis/test/plans/{planId}?api-version=6.0
- Test Suites:
GET https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{planId}/suites/{suiteId}?api-version=6.0
- You will need to call the REST API to get the test plans and test suites. You can use the
- Save the Exported Data:
- Save the response data from the REST API calls into JSON files.
Steps to Import Test Suites and Test Plans
- Create Test Plans and Test Suites in Target Tenant:
- Use the saved JSON files to create test plans and test suites in the target tenant. You will need to call the REST API to create these resources.
- Create Test Plans:
POST https://dev.azure.com/{organization}/{project}/_apis/test/plans?api-version=6.0
- Create Test Suites:
POST https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{planId}/suites?api-version=6.0
- Populate Test Plans and Test Suites:
- Ensure that all the necessary details from the source test plans and test suites are correctly mapped and populated in the target tenant.
Example Scripts
Here are example scripts for exporting and importing test plans and test suites using Azure DevOps CLI and REST API.
Export Script (Python)
import requests
import json
organization = 'ReposMigration'
project = 'VSO Repos Migration'
plan_id = 'YOUR_PLAN_ID'
personal_access_token = 'YOUR_PERSONAL_ACCESS_TOKEN'
# Get Test Plan
url = f'https://dev.azure.com/{organization}/{project}/_apis/test/plans/{plan_id}?api-version=6.0'
response = requests.get(url, auth=('', personal_access_token))
test_plan = response.json()
# Save Test Plan
with open('test_plan.json', 'w') as file:
json.dump(test_plan, file)
# Get Test Suites
url = f'https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{plan_id}/suites?api-version=6.0'
response = requests.get(url, auth=('', personal_access_token))
test_suites = response.json()
# Save Test Suites
with open('test_suites.json', 'w') as file:
json.dump(test_suites, file)
Import Script (Python)
import requests
import json
organization = 'sathishkumarg0353'
project = 'migration'
personal_access_token = 'YOUR_PERSONAL_ACCESS_TOKEN'
# Load Test Plan
with open('test_plan.json', 'r') as file:
test_plan = json.load(file)
# Create Test Plan
url = f'https://dev.azure.com/{organization}/{project}/_apis/test/plans?api-version=6.0'
headers = {'Content-Type': 'application/json'}
response = requests.post(url, headers=headers, data=json.dumps(test_plan), auth=('', personal_access_token))
created_test_plan = response.json()
# Load Test Suites
with open('test_suites.json', 'r') as file:
test_suites = json.load(file)
# Create Test Suites
for suite in test_suites['value']:
url = f'https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{created_test_plan["id"]}/suites?api-version=6.0'
response = requests.post(url, headers=headers, data=json.dumps(suite), auth=('', personal_access_token))
created_test_suite = response.json()
print(f'Created Test Suite: {created_test_suite["id"]}')
More links :