【问题标题】:AutomatedTestName must be specified for automated test runs for AddTestResults Azure DevOps API call必须为 AddTestResults Azure DevOps API 调用的自动化测试运行指定 AutomatedTestName
【发布时间】:2019-07-23 05:25:49
【问题描述】:

我正在尝试在 .NET 中尽可能简单地在 CSV 输入中创建测试结果,看起来最快的方法是首先创建一个空的测试运行,然后将新的测试结果添加到测试中跑。

我已经通过硬编码和运行 Postman 进行了测试,但似乎通过 REST 和 SDK 都收到了相同的错误消息:

必须为自动测试运行指定 AutomatedTestName 未指定 TestPointId 和 TestCaseId。

这是 .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 programatically,但它们似乎都在使用现有的测试结果,我只想在运行中添加新的测试结果。有任何想法吗?

【问题讨论】:

    标签: c# .net azure-devops azure-devops-rest-api tfs-sdk


    【解决方案1】:

    由于您的测试运行是自动化的,您需要将属性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;
    

    【讨论】:

    • 感谢您的回答(以及清理我的问题)。不幸的是,当我把它放进去时,我得到“不应该为手动运行指定automatedTestName”。我将包含用于 TestRun 的代码。
    • @m00nbeam360.0 哦,好吧,你能不能让测试运行不“手动”?您只需要在创建RunCreateModel 时添加isAuutomated: true
    • 感谢您的回复 - 看起来可以创建自动测试运行/结果,但不会与测试用例链接,您之前是否尝试过让它工作?
    • 你的最终解决方案是什么?
    猜你喜欢
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-20
    • 2021-03-08
    • 2019-06-08
    • 2021-03-11
    • 1970-01-01
    相关资源
    最近更新 更多