如何在Visual Studio 2010中精确计时测试运行的时间 [英] How can I precisely time a test run in visual studio 2010

查看:1374
本文介绍了如何在Visual Studio 2010中精确计时测试运行的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的项目使用了一组单元测试,这些单元测试是使用Visual Studio测试运行程序运行的.我想知道测试运行需要多长时间. 测试运行详细信息"屏幕显示了运行的开始和结束时间,但仅显示了最近的时间.目前,我的测试套件需要不到一秒钟的时间才能完成,因此我无法确定我的50个测试套件是否正在< 0.1秒(好!)或1秒(坏!).

I have a suite of unit tests for my project which I run using the visual studio test runner. I want to know how long the test run takes when it runs. The test run details screen shows me the start and end times of the run, but only to the nearest second. My test suite at the moment is taking less than a second to complete, so I can't tell if my suite of 50 tests is taking < 0.1 second (good!) or up to 1 second (bad!).

有什么办法可以达到这种精确度吗?

Is there any way to enable this level of precision?

推荐答案

在根解决方案目录中,测试运行后有一个名为测试结果"的文件夹.如果在其中查找,则每个运行都会吐出一个.TRX文件,该文件带有测试运行的时间戳作为其名称的一部分.打开该文件,您将看到它是一个XML文件,其中包含大量关于测试运行的难以理解的信息.如果您查找XML节点"UnitTestResult",则每个节点将具有一个称为"duration"的属性.这将告诉您每个测试要运行多长时间(假设测试已运行).

In your root solution directory, there is a folder called Test Results following the test runs. If you look in there, each run spits out a .TRX file with timestamp of the test run as part of its name. Open this file, and you'll see that it's an XML file with a bunch of hard-to-read information about the test run. If you look for the XML nodes "UnitTestResult", each will have an attribute called "duration". This will tell you how long each individual test took to run (assuming the test was run).

我写了一个开放源代码实用程序,可以获取这些TRX文件,对其进行解析并生成结果的HTML报告,因此我对此有丰富的经验.它显示给您的一件事是测试持续时间,单个测试,合计的测试类以及整个测试的运行.

I have a good bit of experience with this as I wrote an open source utility that takes these TRX files, parses them, and generates an HTML report of the results. One of the things that it shows you is test time duration, for individual tests, test classes in aggregate, and the test run as a whole.

为避免此问题作为我的工具的插件出现,除非有人好奇,否则我不会发布链接.但是,可以说,您可以从TRX文件中获得测试的执行时间,而无需调试跟踪或控制台,也无需编辑测试代码.

Lest this come off as a plug for my tool, I won't post the link unless someone is curious. But, suffice it to say, you can get the test's execution time from the TRX file without debug trace or the console or editing your test code.

精度高得离谱.对于单个单元测试,示例输入为00:00:00.0015890.

And the precision is ridiculously high. Example entry is 00:00:00.0015890 for a single unit test.

这篇关于如何在Visual Studio 2010中精确计时测试运行的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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