如何在VSTS生成期间以编程方式将附件添加到测试结果?

问题描述:

我正在寻找一种添加自己的附件以测试结果的方法,以便在此处构建完成后可以看到它们...

I'm looking for a way to add my own attachments to test results so that I can see them after a build has completed here...

在构建期间以及测试失败之后,我想以编程方式添加这些内容.附件将是屏幕截图.

I would like to add these programmatically, during a build and after a test has failed. The attachments will be screenshots.

这可能吗?

我快速浏览了 API 参考,但这似乎与在现有测试运行"中添加附件有关,或者在构建时,该方面是用于创建构建定义并触发它们.我可能已经错过了它,但是在测试任务完成期间或之后,我找不到如何从代码中添加附件的方法.

I had a quick look at the API reference but this looked to be concerned with adding attachments to existing test 'runs', or on the build, the side was for creating build definitions and triggering them. I may have missed it but I couldn't find how to add attachments from code during or immediately after a test task had completed.

谢谢

一旦获得失败的测试结果ID,就可以使用

Once you get failed test result id, you could use Rest API to attach a file to test result:

POST https://{instance}/DefaultCollection/{project}/_apis/test/runs/{run}/results/{result}/attachments?api-version={version}
Content-Type: application/json
{
  "stream": { string },
  "fileName": { string },
  "comment": { string },
  "attachmentType": { string }
}