Azure DevOps API 7.0关联测试结果报错(5.0版本正常)的问题咨询
Azure DevOps API 7.0关联测试结果报错(5.0版本正常)的问题咨询
我在使用Azure DevOps API 7.0版本将测试结果关联到“测试运行”时遇到了问题,相同的代码在5.0版本下完全正常,但切换到7.0版本后,就会收到以下错误:
{ "$id": "1", "innerException": null, "message": "TestPointId, testCaseId, testCaseRevision, testCaseTitle must be specified for planned test results.", "typeName": "Microsoft.TeamFoundation.TestManagement.WebApi.InvalidPropertyException, Microsoft.TeamFoundation.TestManagement.WebApi", "typeKey": "InvalidPropertyException", "errorCode": 0, "eventId": 3000 }
以下是我用来关联测试结果到“测试运行”的Python代码:
async def associate_test_results(session, test_run_id, test_points): if not test_points: return headers = get_headers() url = f"https://dev.azure.com/{org_name}/{project_name}/_apis/test/runs/{test_run_id}/results?api-version=7.0" test_case_results = [] results = parse_results_xml() # Calls function that returns the test results for test in results: test_case_id = test.get('test_case_id') outcome = test.get('outcome', "Aborted") error_message = test.get('error_message') # Accessing elapsed time in seconds, and converting to milliseconds elapsed_seconds = test.get('elapsed_seconds', 0) elapsed_ms = elapsed_seconds * 1000 test_point = next((point for point in test_points if point.get("testCase", {}).get("id") == test_case_id), None) if test_point: point_id = test_point.get("id") revision = test_point.get("testCase", {}).get("revision") title = test_point.get("testCase", {}).get("name", f"Test {test_case_id}") result = { "testPoint": {"id": point_id}, "testCase": {"id": test_case_id}, "testCaseRevision": revision, "testCaseTitle": title, "automatedTestName": f"TestClass.{test_case_id}", "automatedTestType": "RobotAutomation", "priority": 1, "outcome": outcome, "state": "Completed", "durationInMs": elapsed_ms, "actionResults": [ { "actionPath": "000001", "outcome": outcome, "comment": f"Test result: {test_case_id}", } ] } if outcome == "Failed" and error_message: result["errorMessage"] = error_message test_case_results.append(result) if test_case_results: try: async with session.post(url, headers=headers, json=test_case_results) as response: if response.status == 200: log.info("Test results successfully associated.") results = await response.json() # Returns the created results await upload_attachments_to_results(session, test_run_id, results) return results else: log.error(f"Error associating results: {response.status}, {await response.text()}") except aiohttp.ClientError as e: log.error(f"Error associating results: {e}")
当使用API 7.0版本运行这段代码时,会返回400 Bad Request错误,错误信息就是前面提到的"TestPointId, testCaseId, testCaseRevision, testCaseTitle must be specified for planned test results."
我的疑问:
- 为什么这个错误只在API 7.0版本出现,而5.0版本却能正常工作?
- 我该如何调整代码,才能成功使用7.0版本API完成测试结果的关联?
我已经仔细检查了testPointId、testCaseId、testCaseRevision和testCaseTitle这些参数,看起来都已经正确传递了,但还是报错,希望能得到大家的帮助或相关见解!
备注:内容来源于stack exchange,提问作者Marcos Vinícius
相关产品推荐
相关产品推荐

