在AssemblyCleanup中将结果文件添加到TestContext [英] Adding result files to TestContext in AssemblyCleanup

查看:72
本文介绍了在AssemblyCleanup中将结果文件添加到TestContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将文件添加到要在TFS中显示的测试运行中,而不是将文件添加到单个测试中.也可以选择仅将文件添加到上一个测试中.

I'm trying to add files to a test run to be shown in TFS, as opposed to adding them to an individual test. Adding files only to the last test would also be an option.

通过将MSTest的TestContext存储在静态变量中,我可以在测试类的AssemblyCleanup方法中访问它,并使用AddResultFile()添加文件.但是,这些文件不会显示为在TFS的Web UI中运行的测试的附件,也不会显示为最后一个测试的附件.

By storing the TestContext of MSTest in a static variable, I can access it in the AssemblyCleanup method of my test class and use AddResultFile() to add my files. However, the files do not appear as attachment of the test run in TFS' web UI, and also do not appear as attachment of the last test.

在测试运行中将文件附加一次的任何方法,是将文件添加到最后一个测试中,还是将其附加到测试运行中?

Any way to attach files once in a testrun, either by adding them to the last test or attaching them to the test run?

推荐答案

使用

Use TFS REST API will be a good option, you can add an attachment to a test run or test result easily.

将文件附加到测试运行:

Attach a file to a test run:

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

Content-Type: application/json

{
  "stream": { string },
  "fileName": { string },
  "comment": { string },
  "attachmentType": { string }
}

将文件附加到测试结果:

Attach a file to a 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 }
}

您可以使用以下代码获取文件的流"字符串:

You can use the following code to get the "stream" string for a file:

Byte[] bytes = File.ReadAllBytes("path");
String file = Convert.ToBase64String(bytes);

这篇关于在AssemblyCleanup中将结果文件添加到TestContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆