Search code examples
c#unit-testingtfs-2015build-definition

How to attach files(*.html/*.xml) to TFS Test reults


I have a test suite with 20 unit tests. I run them through a build definition and at the end publish the results(.trx).Through my test code I generate a folder with each test case, each of which has an .html file and if test case fails a snapshot of the desktop (20 test cases generates 20 folders each of which contains html file). These folders are created locally in the machines where the tests have been run.I wanted to know if I can attach these folders/files to the test results which I publish through my build definition??


Solution

  • When you complete a test the test results (.trx) is generated, So you cannot attach any other files to the test results anymore.

    Update:

    If you just want to attach the files to the test run/result, you can try to use the REST API

    eg:

    POST https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Fabrikam/_apis/test/runs/49/results/100000/attachments?api-version=2.0-preview
    Content-Type: application/json
    {
      "stream": "VXNlciB0ZXh0IGNvbnRlbnQgdG8gdXBsb2FkLg==",
      "fileName": "textAsFileAttachment.txt",
      "comment": "Test attachment upload",
      "attachmentType": "GeneralAttachment"
    }
    

    Update2 :

    Each test (including the automation test) will has a test run ID when running it. the next time to run the same test will be another run ID, it's unique. So, if you want to attach the files to the specific test run, you need to get the test run ID first, the {run} means the specific test run ID.

    You can use the REST API to get the test run list (you can get the test run ID from the list), eg:

    GET http://wxv-xin-12r2:8080/tfs/DefaultCollection/2017ScrumProjectFromVS/_apis/test/runs/