Import Azure DevOps Test Plans from One Environment to Another

Claudia Ferguson

Summary Standardization of Azure DevOps Test Plans and Reusing Them Between Different Organizations

Today we introduce Claudia Ferguson and Mike Stiers to the Scripting Blog. Claudia is a Senior Consultant with the Microsoft Active Directory Migration Services Engineer team, and Mike Stiers is a Microsoft Consultant from Toronto Canada. His focus is to help teams to use scalable infrastructure as code deployments in Azure DevOps. They put together something you will find to be very useful when you need to move DevOps test plans. There is some PowerShell here too (as it’s the Scripting Blog!) but the content is just too cool to not share out!

Claudia and Mike, the Blog is yours today!

Thanks Dr. Scripto! Today we will be discussing moving a DevOps test case into another environment of Azure.

We will use the process below to export Test Cases with Shared Steps from the “Template” SOURCE project into the different DevOps Organization and new project. This process can be used to import Test plans into a new DevOps Organization as well as just a separate DevOps project. It is recommended to have a separate project for each customer and a separate project where you will maintain a template for the test plans.

General description

Export/Import shared steps by using Export and Import CSV option. (Reference link: https://docs.microsoft.com/en-us/azure/devops/boards/queries/import-work-items-from-csv?view=azure-devops)

NOTE:

This is a known issue with Shared Steps so you will not be able to follow usual process for exporting parent/child relationship like you can do with other work items such as Epic/Feature/UserStory where you can just export all of them at once into one csv.

You will need to export separately Shared Steps and Test Cases in two separate csv files.

Export Shared Steps into csv file from SOURCE DevOps

1. Export all Shared steps by using custom query as shown in the screenshot below.

  • Click on Boards -> Query
  • Under Queries, select All
  • Click on New Query
  • Create “Shared Steps Only” Query as shown below

NOTE: You will need to add an additional column “Steps” in the query

  • Click on “Column options” in the query Editor, and then add “Steps” column.
  • Save the query “Shared Steps Only”

Image items

Image items 1

Image items 2

2. Click on “Shared Steps Only” query and then click Run query.

3. Export the results of the query to CSV by clicking “Export to CSV” option

Image items 3

4. Edit shared steps spreadsheet. Rename ID column to Description

Import Shared Steps into TARGET DevOps

5. Import Shared steps that you just modified

  • Click on Boards -> Query -> Import Work Items

Image items 4

6. Click Save Items

Image items 5

NOTE: Description column will have old IDs and ID column will have new IDs

7. Export to CSV with new IDs. Name the export file SharedStepsReady.csv

 

Export Test Cases from the SOURCE DevOps

8. Export Test Cases into csv file “TestCaseswithStepsIDsColumn.csv”

  • Click on Boards -> Query
  • Under Queries, select ALL

Image items 6

NOTE: You will need to add an additional column “Steps” in the query as shown below

Image items 7

9. Run PowerShell Script that we are providing. The new file should be created by PowerShell and called replaced.csv

10. Script for download

<#
Reference:
https://docs.microsoft.com/en-us/azure/devops/boards/queries/import-work-items-from-csv?view=azure-devops

Prerequisites:
-You will need to export all shared steps and test cases as two separate files from SOURCE DevOps

Shared Steps
-Export all Shared steps
-Edit shared steps spreadsheet. Rename ID column to Description
-Import Shared Steps into TARGET DevOps
-Click Save Items

-From TARGET DevOps export all shared steps to CSV with new IDs. Name the export file SharedStepsReady.csv

Test Cases
-Export all Test Cases
-From SOURCE DevOps export all Test Cases into csv file "TestCaseswithStepsIDsColumn.csv"

-Run PowerShell Script. The new file should be exported called replaced.csv
-Delete the ID column in the test cases spreadsheet
-Import test cases csv
#>

$sharedStepsCSV = "SharedStepsReady.csv"
$testCasesCSV = "TestCaseswithStepsIDsColumn.csv"

$sharedSteps = import-csv $sharedStepsCSV

$testCases = Get-Content $testCasesCSV
$sharedStepsHash = @{}
Foreach ($sharedStep in $sharedSteps)
{
$newID = $sharedStep.id
$oldID = $sharedStep.description
$sharedStepsHash.add($oldID,$newID)
}

Foreach ($hash in $sharedStepsHash.GetEnumerator()) {
$testCases = $testCases -replace $hash.Name, $hash.Value
$hash.Name + " " + $hash.Value
}
Set-Content -Path replaced.csv -Value $testCases

11. Delete the ID column in the test cases spreadsheet called replaced.csv and save it without IDs column

 

Import Test Cases into TARGET DevOps

12. Import test cases csv that you just saved called replaced.csv

13. Once you imported all the work items, create a new Test Plan in the TARGET DevOps

14. Click on the Define Tab, then New Test Case, and select Add Existing Test Cases

Image items 8

15. Click Run a Query, then select all the test cases and click Add Test Cases

Image items 9

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Forum. See you tomorrow. Until then, peace.

Your good friend, Doctor Scripto

PowerShell, Azure, Doctor Scripto, Claudia Ferguson, Mike Stiers

 

 

0 comments

Discussion is closed.

Feedback usabilla icon