You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将PowerShell Pester自动化测试关联至Azure DevOps手动测试用例?

如何将Pester自动化测试与Azure DevOps手动测试用例关联并同步执行结果

背景

  • 使用PowerShell Pester Framework编写自动化测试,同时在Azure DevOps的Test Plans>Test Suites中维护了与测试Describe块同名的手动测试用例
  • 通过CI/CD流水线执行测试并发布构件,流水线运行后会在Test Results中生成带Run Id的测试记录,但Test Suite>Execute>Outcome及进度报告标签页未同步更新结果
  • 每个手动测试用例的「Associated Automation」子标签页为空且处于禁用状态,尝试多种方式关联自动化测试脚本均未成功

现有Pester测试代码(IntelliJ编写)

# Import Pester and Az Storage modules

Import-Module Pester
#Install-Module Az.Storage
Import-Module Az.Storage

# Define the Pester test script
Describe "Verify workflow trigger and validate the logs in Storage Table" {

    It "To trigger Azure Logic Apps workflow Interface" {
        $url = "<subject url>"

        # Headers for the request
        $headers = @{
            "Content-Type" = "application/json"
            "Accept" = "*/*"
        }

        # Body needs to be converted to JSON format
        $body = @{
            type = "charges"
            invoiceId = "invoice"
            reference = "761i6"
        } | ConvertTo-Json

        # Sending the POST request with JSON body
        $response = Invoke-WebRequest -Uri $url -Method POST -Headers $headers -Body $body

        # Validate the status code
        $response.StatusCode | Should -Be 200

        if ($response.StatusCode -eq "200") {
            Write-Host "Test passed: Response code is: 200"
        }
    }


    It "To verify Azure Logic Apps workflow in Storage Table" {
        $todayDate = Get-Date -Format "yyyy-MM-dd"
        Write-Output $todayDate
        Write-Host "Today's date is: $todayDate"
        $todayDate | Should -Match "^\d{4}-\d{2}-\d{2}$"

        $appId = "<app id>"
        $tenantId = "<tenant id>"
        $clientSecret = "<secret>"  # Mock value for client secret in tests
        $secureClientSecret = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
        $psCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $appId, $secureClientSecret
        Connect-AzAccount -ServicePrincipal -Credential $pscredential -Tenant $tenantId
        $resourceGroupName = "<res group name>"
        $storageAccountName = "<storage acc name>"
        $tableName = "<storage table>"
        $storageKeys = Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName
        $primaryKey = $storageKeys.Value[0]
#        Write-Host "Primary Key: $primaryKey"  # You can use Write-Host to print it in the console
#        Write-Output $primaryKey
        $context = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $primaryKey
        $storageTable = Get-AzStorageTable -Name $tableName -Context $context
        $cloudTable = $storageTable.CloudTable
        $output = Get-AzTableRow -table $cloudTable -columnName "InterfaceId" -value "Invoice" -operator Equal

    }
}

流水线YAML配置(发布测试结果任务)

# Publish the test results to the Azure DevOps Test tab with a custom name
- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'NUnit'
    testResultsFiles: '$(System.DefaultWorkingDirectory)/PesterReport/TestResults.xml'
    testRunTitle: 'Test Results'
    testSelector: 'testPlan'
    testPlan: '180'  # Reference the Test Plan ID
    testSuite: '221'  # Reference the Test Suite ID
    mergeTestResults: true

核心需求

  • 解决手动测试用例「Associated Automation」字段无法关联Pester脚本的问题
  • 实现每次流水线运行时,自动将测试结果同步更新到对应手动测试用例的Outcome字段及测试套件的进度报告中

内容的提问来源于stack exchange,提问作者Srikant Kanchumurthi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 20:22:32