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

如何通过TestCase ID或WIQL查询获取VSTS的测试运行结果?

Absolutely! You’ve got two reliable ways to pull test run outcomes by Test Case ID in Azure DevOps (formerly VSTS)—either via direct REST API calls or using WIQL (Work Item Query Language). Let’s walk through both:

1. Use the REST API Test Results Endpoint

You can use the Test Results - List endpoint to filter results specifically by your Test Case ID, no need to know individual run IDs upfront. Here’s how:

  • The request URL (replace placeholders with your actual values):
    GET https://dev.azure.com/{organization}/{project}/_apis/test/results?testCaseId={your-test-case-id}&api-version=7.1-preview.6
    
  • Key details:
    • testCaseId: Replace with the ID of the test case you’re targeting
    • api-version: Use a recent version (you can check Azure DevOps documentation for the latest stable option if preview builds aren’t ideal for your workflow)
  • Response output: The returned data includes all test results for that test case, with critical fields like outcome (Passed, Failed, Skipped, etc.), associated test run ID, test run title, and completion timestamps.
2. Use WIQL (Work Item Query Language)

WIQL lets you query test result entities directly, which is a flexible approach if you prefer a query-based workflow. Here’s how to implement it:

  1. Craft a WIQL query to filter test results by your target Test Case ID:
    SELECT
      ResultId,
      TestCaseId,
      Outcome,
      RunId,
      Title,
      CompletedDate
    FROM
      TestResult
    WHERE
      TestCaseId = {your-test-case-id}
    
  2. Execute the query via the Queries - Query By Wiql API:
    • Send a POST request to this URL:
      POST https://dev.azure.com/{organization}/{project}/_apis/wit/wiql?api-version=7.1-preview.2
      
    • Include this JSON request body (replace the query with your own):
      {
        "query": "SELECT ResultId, TestCaseId, Outcome, RunId, Title FROM TestResult WHERE TestCaseId = 12345"
      }
      
  3. The response will return a list of matching test results, including the Outcome value you need. You can expand the query to pull additional fields like Tester or RunTitle if required.

Quick Extra Tips

  • Permissions: Ensure your service account or personal access token (PAT) has the View test runs permission enabled for the project.
  • Full run details: If you need more context about the test run itself (like run owner or configuration), take the RunId from your results and call the Test Runs - Get endpoint:
    GET https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}?api-version=7.1-preview.3
    

内容的提问来源于stack exchange,提问作者Hansmukh Jain

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 04:18:08