c# - 必须为 AddTestResults Azure DevOps API 调用的自动化测试运行指定 AutomatedTestName
问题描述
我正在尝试在 .NET 中尽可能简单地在 CSV 输入中创建测试结果,看起来最快的方法是首先创建一个空的测试运行,然后将新的测试结果添加到测试运行中。
我已经通过硬编码和运行 Postman 进行了测试,但似乎通过 REST 和 SDK 都收到了相同的错误消息:
当未指定 TestPointId 和 TestCaseId 时,必须为自动化测试运行指定 AutomatedTestName。
这是.NET代码:
var testCase = await testPlanClient.GetTestCaseAsync(_teamProject, {planId}, {suiteId}, "1141");
var testPoint = testCase[0].PointAssignments.SingleOrDefault(p => p.ConfigurationId == testConfiguration.Id);
var pointId = testPoint.Id;
var run = new RunCreateModel(name: testRun.Name, state: "NotStarted", isAutomated: false, plan: new ShallowReference({planid}), pointIds:new int[] { 1654 });
...
testResultList.Add(new TestApi.TestCaseResult()
{
TestCaseTitle = testResult.TestCaseTitle,
TestCase = new ShallowReference(id: testResult.TestCaseId.ToString()),
TestPoint = new ShallowReference(id: "1654"),
TestCaseReferenceId = testResult.TestCaseId,
Outcome = SetOutcome(testResult.Outcome),
Configuration = new ShallowReference(id: testConfiguration.Id.ToString()),
CreatedDate = testResult.CreatedDate,
StartedDate = testResult.StartedDate,
CompletedDate = testResult.CompletedDate
});
}
List<TestApi.TestCaseResult> createdTestResults = new List<TestApi.TestCaseResult>();
createdTestResults = await testClient.AddTestResultsToTestRunAsync(testResultList.ToArray(), _teamProject, testRunId);
邮差:
POST https://dev.azure.com/{org}/{project}/_apis/test/Runs/{runId}/results?api-version=5.1
[
{
"testCaseTitle": "testcase1",
"testPoint": {
"id": 17
},
"testCase": {
"id": 1141
},
"priority": 1,
"outcome": "Passed"
}
]
我在上面的示例中同时输入了 TestPointId 和 TestCaseId ,如果我仍然收到相同的错误消息,两者似乎都不起作用。我查看了类似的答案,例如:How to Add test results to a test run in VSTS using Rest API programmatically但他们似乎都在使用现有的测试结果,我只想将新的测试结果添加到运行中。有任何想法吗?
解决方案
因为您的测试运行是自动化的,所以您需要向 提供属性AutomatedTestName
,TestCaseResults
例如:
TestCaseResults results = new TestCaseReults()
{
TestCaseTitle = "test",
AutomatedTestName = "name",
TestCase = new ShallowReference(id: "32"),
TestPoint = new ShallowReference(id: "1"),
Outcome = "Passed"
}
List<TestCaseResult> list = new List<TestCaseResult>();
list.add(results);
var response = test.AddTestResultsToTestRunAsync(list.ToArray(), "project", 3214 // Test Run ID).Result;
推荐阅读
- graphql - 重复的“graphql”模块,两个端点:NextJS GraphQL Server API 路由?
- android - dlopen 因“找不到库错误”而失败 android ndk
- c - 我正在编译为课程构建的内核并尝试构建它会出错
- javascript - 如何触发此动画在视口中开始一次?
- python - Pandas - 编写一个可重用的 Python 函数来聚合和计算加权平均值
- salesforce - 针对经验用户的 Salesforce 身份验证提供商问题
- excel - 有没有办法在每次运行代码时向选定范围添加一个新行?并在退出时保存这个?
- skia - skparagraph 库中缺少符号
- python - 带有时间表的Python调度作业以及套接字模块不起作用
- vue.js - 构建后如何在 vuejs 或 quasar 中管理 .env 文件?