Skip to main content
351

Publishing JUnit to Azure Test Plan with PowerShell Module

Created
Active
Last edited
Viewed 369 times
1 min read
Part of CI/CD Collective
2

My current challenge revolves around Azure Test Plan's robust test management features, which unfortunately do not include built-in support for importing JUnit test results. This poses an obstacle for teams relying on JUnit for testing, as it disrupts the seamless integration and comprehensive reporting within Azure DevOps.

To address this issue, one potential remedy involves harnessing annotations and REST APIs within the test framework itself. By embedding annotations into the test code and utilizing REST APIs to interact with Azure Test Plan, teams can create a tailored integration that bridges the gap between JUnit and Azure Test Plan. However, successfully implementing this solution necessitates careful consideration of both the capabilities of the test framework and the complexities of Azure Test Plan's APIs.

This is why I created this simple PowerShell module that will assist anyone interested in publishing their JUnit Test Report to Azure TestPlan.

PowerShell Command for Importing JUnit Results

The Import-JUnitToAzTestPlan PowerShell module simplifies the process of importing JUnit test results into Azure Test Plan, streamlining the integration of JUnit tests into your CI/CD pipelines.

Getting Started: Step-by-Step Guide

  1. Install the Module: Begin by installing the "Import-JUnitToAzTestPlan" module from the PowerShell Gallery using the Install-Module cmdlet.

    Install-Module -Name Import-JUnitToAzTestPlan
    
  2. Execute the Import Command: Utilize the Import-JUnitToAzTestPlan command, specifying the required parameters such as the Azure DevOps organization URL, project URL, test plan ID, and JUnit test result file path.

    Import-JUnitToAzTestPlan -Token "$env:TOKEN" `
    -ProjectUrl "https://dev.azure.com/yourorganization/yourproject" `
    -TestPlanID "<TargetTestPlanID>" `
    -TestSuiteID "<TargetTestSuiteID>" `
    -TestConfiguration "<TargetTestConfiguration>" `
    -ExecutionReport "path/to/your/junit-results.xml"
    
  3. Customize Parameters: Adjust the parameters according to your project's configuration and requirements. For example, specify the appropriate test configuration and test suite ID.

  4. Integration with CI/CD Pipelines: Incorporate the import command into your CI/CD pipeline workflow, ensuring seamless execution of JUnit tests and automatic import of test results into Azure Test Plan.

    • Task on Azure Pipeline YAML

      - task: PowerShell@2
        inputs:
          targetType: 'inline'
         script: |
            Import-JUnitToAzTestPlan -Token "$env:TOKEN" `
                -ProjectUrl "https://dev.azure.com/yourorganization/yourproject" `
                -TestPlanID "<TargetTestPlanID>" `
                -TestSuiteID "<TargetTestSuiteID>" `
                -TestConfiguration "<TargetTestConfiguration>" `
                -ExecutionReport "path/to/your/junit-results.xml"
          pwsh: true
      
    • pwsh is set to True as powershell core required for the module.

Results:

enter image description here