Reputation: 197
With the aim of reporting from an external test framework to a VSTS build report - what is the minimum required in a VSTS build definition, to check the ability to post a test result to a test run via the API?
At the moment, I have a minimal proof of concept VSTS build definition containing:
While the above VSTS build is running, I am trying to post a generic 'test result' in with JSON:
[
{
"testCaseTitle": "myTestCaseTitle",
"automatedTestName": "myAutomatedTestName",
"priority": 1,
"outcome": "Passed"
}
]
To the current test run, at:
https://{instance}/DefaultCollection/{project}/_apis/test/runs/{run}/results?api-version={version}
However it still seems during the build test run, the run is not available on the API to post new test results to until the build completes. And once it completes, it is also not available to post results to, with the server response stating:
TestCaseResults cannot be added or updated for a test run which is in Completed state
So, what is the minimum required in a build definition to open up a valid window with which to post generic test results, if this is even possible? (And can you avoid specifying a particular {run} number, targetting the current run?)
Upvotes: 0
Views: 576
Reputation: 197
Quick answer for posting results from an external testing framework into VSTS against a product build created in VSTS:
Define a build process which builds product
Post a new 'test run' against existing build (specify the buildID within the json body)
{ "name": "myTestRun", "build": { "id": "629" }, "isAutomated": true, "state": "Waiting" }
Have your bespoke test controller launched, with it running required tests
As results become available from your test controller, post test results against the run created earlier, eg:
[ { "testCaseTitle": "myTestCaseTitle", "automatedTestName": "myAutomatedTestName", "priority": 1, "outcome": "Passed" } ]
body:
{
"name": "myTestRun",
"state": "Completed",
"comment":"All tests have been run"
}
Upvotes: 0
Reputation: 33708
You can update the test run state first, then add the test result to that test run.
Simple sample steps:
JSON body:
{
"state":"InProgress"
}
JSON body:
[
{
"testCaseTitle":"TestMethod1",
"automatedTestName": "UnitTestProject1.UnitTest1.TestMethod1",
"outcome": "Passed"
}
]
Regarding thread sleep:
Script:
Start-Sleep -s 3600
Node: if you need to wait a long time (more than 30 minutes), you need to use private agent, about setup a private agent, you can refer to: Deploy an agent on Windows
Upvotes: 1