必须为AddTestResults Azure DevOps API调用的自动化测试运行指定AutomatedTestName

时间:2019-07-23 05:25:49

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

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

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

  

必须在以下情况下为自动测试运行指定AutomatedTestName:   没有指定TestPointId和TestCaseId。

这是.NET代码:

var run = new RunCreateModel(name: testRun.Name, state: "NotStarted");

...

testResultList.Add(new TestApi.TestCaseResult()
                {
                    TestCaseTitle = testResult.TestCaseTitle,
                    TestCase = new ShallowReference(id: testResult.TestCaseId.ToString()),
                    TestPoint = new ShallowReference(id: "1"),
                    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": 1
    },
    "testCase": {
        "id": 1141
    },
    "priority": 1,
    "outcome": "Passed"
  }
]

在上面的示例中,我同时输入了TestPointId和TestCaseId,如果我仍然收到相同的错误消息,两者似乎都无法正常工作。我研究了类似的答案,例如:How to Add test results to a test run in VSTS using Rest API programatically,但它们似乎都在使用现有的测试结果,我只想在运行中添加新的测试结果。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

由于测试运行是自动化的,因此需要向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;