如何以编程方式生成 trx 文件? [英] How to programmatically generate a trx file?

查看:31
本文介绍了如何以编程方式生成 trx 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索过这个主题,没有找到任何好的信息来一步一步地做,所以我研究了它并在这里分享.这是一个简单的解决方案.

I have searched on this topic, didn't find any good info to do it step by step, so I studied it and shared it here. Here is an easy solution.

推荐答案

在你的 VisualStudio 安装中找到 vstst.xsd 文件,使用 xsd.exe 生成一个 .cs 文件:

Find the vstst.xsd file in your VisualStudio installation, use xsd.exe to generate a .cs file:

xsd.exe/classes vstst.xsd

xsd.exe /classes vstst.xsd

生成的 vstst.cs 文件包含定义 trx 文件中每个字段/元素的所有类.

The resulted vstst.cs file contains all classes defining every fields/elements in a trx file.

您可以使用此链接了解 trx 文件中的一些字段:http://blogs.msdn.com/b/dhopton/archive/2008/06/12/helpful-internals-of-trx-and-vsmdi-文件.aspx

you can use this link to learn some fields in a trx file: http://blogs.msdn.com/b/dhopton/archive/2008/06/12/helpful-internals-of-trx-and-vsmdi-files.aspx

您还可以使用从 mstest 运行生成的现有 trx 文件来学习该领域.

you can also use an existing trx file generated from a mstest run to learn the field.

有了 vstst.cs 和你对 trx 文件的了解,你可以编写如下代码来生成一个 trx 文件.

with the vstst.cs and your knowledge of trx file, you can write code like following to generate a trx file.

TestRunType testRun = new TestRunType();
ResultsType results = new ResultsType();
List<UnitTestResultType> unitResults = new List<UnitTestResultType>();
var unitTestResult = new UnitTestResultType();
unitTestResult.outcome = "passed";
unitResults.Add( unitTestResult );

unitTestResult = new UnitTestResultType();
unitTestResult.outcome = "failed";
unitResults.Add( unitTestResult );

results.Items = unitResults.ToArray();
results.ItemsElementName = new ItemsChoiceType3[2];
results.ItemsElementName[0] = ItemsChoiceType3.UnitTestResult;
results.ItemsElementName[1] = ItemsChoiceType3.UnitTestResult;

List<ResultsType> resultsList = new List<ResultsType>();
resultsList.Add( results );
testRun.Items = resultsList.ToArray();

XmlSerializer x = new XmlSerializer( testRun.GetType() );
x.Serialize( Console.Out, testRun );

请注意,由于项目"字段上的某些继承问题,例如 GenericTestType 和 PlainTextManualTestType(均源自 BaseTestType),您可能会收到 InvalidOperationException.谷歌搜索应该有一个解决方案.基本上将所有项目"定义放入 BaseTestType.这是链接:抛出异常的 TestRunType 序列化

note that you may get InvalidOperationException due to some inheritance issues on "Items" fields, like GenericTestType and PlainTextManualTestType (both derived from BaseTestType). There should be a solution by googling. Basically put all "Items" definition into BaseTestType. Here is the link: Serialization of TestRunType throwing an exception

为了使trx文件能够在VS中打开,需要输入一些字段,包括TestLists、TestEntries、TestDefinitions和results.您需要链接一些 guid.通过查看现有的 trx 文件,不难找到.

to make the trx file be able to open in VS, there are some fields you need to put in, including TestLists, TestEntries, TestDefinitions and results. You need to link up some of the guids. By looking into an existing trx file, it's not hard to find out.

祝你好运!

这篇关于如何以编程方式生成 trx 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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