通过 API 获取 TFS 中失败的 TestCaseResult 的 StackTrace [英] Getting the StackTrace for a TestCaseResult that Failed in TFS via API

查看:29
本文介绍了通过 API 获取 TFS 中失败的 TestCaseResult 的 StackTrace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ITestCaseResult 有一个属性ErrorMessage"

ErrorMessage 属性的最大大小为 527 字节,这不足以存储重量级的异常结构,不幸的是似乎没有合适的 Exception 属性来存储一个.

The ErrorMessage property has a max size of 527bytes, which is not enough to store weighty Exception structures and unfortunately does not seem to have an appropriate Exception property to store one in.

我的问题是,当测试失败时,您如何获得 StackTrace?我知道它可用,因为 GUI 可以在 Visual Studio 中提取它

My question is, when a test fails, how do you get the StackTrace? I know its available because the GUI can pull it up in Visual Studio

正如您所看到的,与 ITestCaseResult 关联的 ErrorMessage 被缩短了.(如果您使用浏览器进行缩放,图像会恢复清晰度.)

And as you can see the ErrorMessage associated with a ITestCaseResult is cut short. (If you zoom with your browser the image regains its clarity.)

我在 RunInfo 对象中发现了一个可能的线索:http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.common.runinfo.aspx.

I found a possible lead in the RunInfo object : http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.common.runinfo.aspx.

它具有适当的异常结构,似乎与运行相关联,但我无法将 ITestCaseResultRunInfo 对象之间的点联系起来.我可能在吠错树.

It has an proper exception structure, and seems to be associated with a run, but I can't connect the dots between a ITestCaseResult and a RunInfo Object. I might be barking up the wrong tree.

推荐答案

我认为 Visual Studio 从 TRX 文件中获取此信息,该文件存储为测试运行的附件.

I think Visual Studio gets this info from the TRX file which it stores as an attachment to the test run.

我得到的附件如下:

            TfsTeamProjectCollection tfsCollection = new TfsTeamProjectCollection(new Uri("http://tfsserver:8080/tfs/CTS"));
            ITestManagementService tfsStore = tfsCollection.GetService<ITestManagementService>();
            ITestManagementTeamProject tcmProject = tfsStore.GetTeamProject("MyProject");

            // Get Test Run Data by Build
            ITestRun thisTestRun = tcmProject.TestRuns.ByBuild(new Uri("vstfs:///Build/Build/" + buildnum)).First();
            foreach (ITestAttachment attachment in thisTestRun.Attachments)
            {
                if (attachment.AttachmentType == AttachmentTypes.TrxTmiTestRunSummary)
                {
                    WebRequest request = HttpWebRequest.Create(attachment.Uri);
                    request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                    WebResponse response = request.GetResponse();
                    using (System.IO.Stream responseStream = response.GetResponseStream())
                    {
                        System.IO.StreamReader reader = new System.IO.StreamReader(responseStream);
                        trxFile.Load(reader);
                    }

                    break;
                }
            }

然后为了获取命名测试的堆栈跟踪,我执行了以下操作:

And then to get the stack trace for a named test I did the following:

                XmlNamespaceManager nsmgr = new XmlNamespaceManager(trxFile.NameTable);
                nsmgr.AddNamespace("vstt", "http://microsoft.com/schemas/VisualStudio/TeamTest/2010");

                // get result node for this testcase from trx file
                XmlNode node =
                    trxFile.SelectSingleNode(
                        "//vstt:UnitTestResult[@testName=\"SourceWorkflowAsSvcWhenErrorConvertingFile\"]/vstt:Output/vstt:ErrorInfo",
                        nsmgr);
                if (node != null)
                {
                    Console.WriteLine("Stack Trace: " + node.InnerText);
                }

我使用此参考获取获取附件的代码:http://social.msdn.microsoft.com/Forums/vstudio/en-US/7fecbac7-7c42-485f-9dd2-5bcb4e71fc39/retrieving-trx-file-stored-in-tfs-for-a-test

I used this reference to get the code for getting attachment: http://social.msdn.microsoft.com/Forums/vstudio/en-US/7fecbac7-7c42-485f-9dd2-5bcb4e71fc39/retrieving-trx-file-stored-in-tfs-for-a-test

这篇关于通过 API 获取 TFS 中失败的 TestCaseResult 的 StackTrace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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