1
votes

I have an existing test result and I'd like to update the "Tested build" field for the test result if possible. I've looked at the REST API doc (https://docs.microsoft.com/en-us/rest/api/azure/devops/test/results/update?view=azure-devops-rest-5.0) and I think that I've called the PATCH method correctly but while a 200 is returned, the test result in the UI doesn't change with "not available".

Is there a way to change this field or is it read-only?

PATCH https://dev.azure.com/{org}/{project}/_apis/test/Runs/{runId}/results?api-version=5.0

Auth: PAT for user who has Test Plans license

JSON request body: 
[
    {
        "id": "100000",
        "build": {
            "id": "206",
            "name": {buildDefinitonName},
            "url": "https://dev.azure.com/{org}/{projectguid}/_apis/build/Builds/206"
        }
    }
]

JSON response body: 
{
    "count": 1,
    "value": [
        {
            "id": 100000,
            "project": {},
            "lastUpdatedDate": "2019-06-13T17:18:56.073Z",
            "priority": 0,
            "url": "",
            "lastUpdatedBy": {
                "displayName": null,
                "id": null
            }
        }
    ]
}

I've also tried with the .NET SDK but no luck:

...
var build = await buildClient.GetBuildAsync(projectGuid, 206);

var testResult = await testClient.GetTestResultByIdAsync(projectGuid, {runId}, 100000);

testResult.Build = new Microsoft.TeamFoundation.TestManagement.WebApi.ShallowReference
     {
         Id = build.Id.ToString(),
         Name = build.Definition.Name,
         Url = build.Url
     };

TestCaseResult[] results = new TestCaseResult[] { testResult };

var outcome = await testClient.UpdateTestResultsAsync(results, teamProject, {runId});

(outcome shows Build = null)

1
Does my answer solve your puzzle now? Feel free to let us know the latest status:-)Merlin Liang - MSFT

1 Answers

0
votes

called the PATCH method correctly but while a 200 is returned, the test result in the UI doesn't change with "not available".

To explain this, first need to know what does the response code 200OK defined:

" It represent a standard response for successful HTTP requests. The actual response will depend on the request method used.

As it say, 200OK just mean that your request URL, body and method are all correct and request successfully. But, for actually put/patch action, it depend on the actual situation. So 200OK does not also mean that the operation is been completed and succeed.

enter image description here

So, for "Tested build" field for the test result in Azure Devops,

Is there a way to change this field or is it read-only?

No, you could not change it with API, even if with UI. It just read only.

You know, after test execution end, the build associated with this test is fixed, this is the actual truth. So, you could not change it, it just read only to tell you what is tested build.