Azure DevOps中如何将测试用例/测试点关联至已完成的测试运行?
Azure DevOps中已完成测试运行与测试用例/测试点的关联方案
可以关联,但已完成的测试运行无法通过UI直接操作,需要结合API处理历史数据,同时调整流水线配置避免后续再出现该问题。
一、处理已完成的历史测试运行
- 通过Azure DevOps REST API修改关联关系:
- 先获取目标测试运行的结果ID,以及需要关联的测试点ID(测试点ID可在测试计划的测试点详情页查看)。
- 调用
Test Results - Update接口,为指定测试结果设置testPointId参数完成关联。可以用Python编写脚本批量处理,示例逻辑如下:import requests from azure.devops.connection import Connection from msrest.authentication import BasicAuthentication # 配置Azure DevOps信息 organization_url = "https://dev.azure.com/your-org" project = "your-project" personal_access_token = "your-pat-token" # 建立连接 credentials = BasicAuthentication('', personal_access_token) connection = Connection(base_url=organization_url, creds=credentials) # 获取测试运行结果 test_client = connection.clients.get_test_client() test_run_id = 12345 # 替换为你的测试运行ID test_results = test_client.get_test_results(test_run_id, project) # 关联测试点 target_test_point_id = 67890 # 替换为你的测试点ID for result in test_results: if result.test_case_title == "你的测试用例标题": # 匹配对应测试结果 result.test_point_id = target_test_point_id test_client.update_test_result(result, test_run_id, project)
二、调整流水线,让后续测试自动关联测试点
- 使用
pytest-azurepipelines插件:该插件可自动将pytest测试与Azure DevOps测试用例关联,只需在测试方法上添加标记指定测试用例ID,示例代码:
流水线中执行pytest时启用该插件,生成的测试结果会自动关联对应测试点。import pytest @pytest.mark.azuredevops(test_case_id=12345) def test_my_function(): assert 1 + 1 == 2 - 配置
Publish Test Results任务:在任务高级设置中勾选“Associate test results with test cases”,确保XML报告中的测试用例标识能匹配Azure DevOps中的测试点。 - 改用
Run Functional Tests任务:该任务可直接指定测试计划、测试套件或测试点,执行pytest测试时会自动将结果与指定测试点关联,适合需要严格绑定测试计划的场景。
内容的提问来源于stack exchange,提问作者Andrew Littell
相关产品推荐
相关产品推荐

