简体   繁体   English

Visual Studio 2012 单元测试报告

[英]Visual Studio 2012 Unit Test Report

I need to create some report of the execution of my unit test cases (quantity of tests passed, failed and ignored).我需要创建一些关于我的单元测试用例执行的报告(通过、失败和忽略的测试数量)。 I looked around the internet but I didn't find any way to generate this.我环顾了互联网,但没有找到任何方法来生成它。 Does someone knows a simple (or complex) way to generate a unit test report locally?有人知道在本地生成单元测试报告的简单(或复杂)方法吗? (I said locally because I have found a solution using the test manager but is not feasible to me righ now). (我在本地说是因为我已经找到了使用测试管理器的解决方案,但现在对我来说不可行)。

There is no option from the Visual Studio UI, but this can be accomplished from the command line. Visual Studio UI 没有选项,但这可以从命令行完成。 navigate to your solution directory and run the following command from the Visual Studio 2013 command line:导航到您的解决方案目录并从 Visual Studio 2013 命令行运行以下命令:

vstest.console.exe /logger:trx .\\TestProject\\bin\\debug\\YourUnitTestAssembly.dll vstest.console.exe /logger:trx .\\TestProject\\bin\\debug\\YourUnitTestAssembly.dll

This will create a TestResults folder under your solution root and drop a .trx file.这将在您的解决方案根目录下创建一个 TestResults 文件夹并放置一个 .trx 文件。 By opening that file into Visual Studio you should see something like this:通过在 Visual Studio 中打开该文件,您应该会看到如下内容:

在此处输入图片说明

The .trx file is easy to parse XML and can be converted into human readable data using an XSLT, as explained in this other question . .trx 文件很容易解析 XML,并且可以使用 XSLT将其转换为人类可读的数据,如另一个问题中所述

Normally Visual Studio creates this file during the run, but deletes it afterwards.通常 Visual Studio 在运行期间创建此文件,但随后将其删除。 It looks like my instance of Visual Studio will actually create such a trx file and keep it in a $(solutionroot)\\TestResults\\{GUID} directory when I use the Analyze code coverage feature:当我使用分析代码覆盖率功能时,看起来我的 Visual Studio 实例实际上会创建这样一个 trx 文件并将其保存在$(solutionroot)\\TestResults\\{GUID}目录中:

在此处输入图片说明

在此处输入图片说明

To see if your version of Visual studio has the Trx logger installed, run the following command from a Visual Studio command prompt:要查看您的 Visual Studio 版本是否安装了Trx记录器,请从 Visual Studio 命令提示符运行以下命令:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM