Minimum required to post a test result to a test run via API? RRS feed

  • Question

  • Hi, as a proof of concept for VSTS receving tests results via API, I am aiming to:

    1. create an emptyish build definition

    2. have it present a window of opportunity to receive test results posted via the api
    (So far I've done this by calling a visual studio solution that waits 60 seconds, but perhaps a powershell command would have been enough)

    Whilst running the above build process, I have tried firing in the following test result request:

    POST https://{instance}/DefaultCollection/{project}/_apis/test/runs/{run}/results?api-version={version}

    However, whilst the build process is running, until it completes, I am returned:
    Test run with id {id} could not be found. It may have been deleted

    So, three questions:

    1. How can you automatically post to the current test {run}, without finding which number this would be? (Is there a variable which can be passed in the request to indicate latest?)

    2. My build process didn't seem to be presenting a window of opportunity to listen for any incoming test results. What step should I add or change to achieve this?

    3. Our test cases associated with a build, may not be defined in VSTS. Will it still be acceptable to post test results back, against no defined test cases? For example with json:



        "testCaseTitle": "myTestCaseTitle",

        "automatedTestName": "myAutomatedTestName",

        "priority": 1,

        "outcome": "Passed"



    Many thanks

    • Edited by pretzelzzz Friday, June 9, 2017 4:04 PM
    Friday, June 9, 2017 4:02 PM

All replies

  • If you create an empty build definition it won't create a test run. You need to have any Test Tasks to create a Test run.
    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.

    Saturday, June 10, 2017 10:52 AM
  • Thank you for your response. I can confirm that I have the following in my build definition:

    Build Solution

    VsTest Test Assemblies   (runs a single MSTest VS test, which contains System.Threading.Thread.Sleep(60000);  to create a minute window in which to post in test results from an external application)

    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, looking for a way to present a window of opportunity in which the build will listen for incoming test results.

    Monday, June 12, 2017 8:29 AM