简体   繁体   English

Visual Studio 2012 - 代码覆盖 - 如何正确执行?

[英]Visual Studio 2012 - code coverage - how to do it correctly?

I'm trying to automate code coverage with unit test. 我正在尝试使用单元测试自动化代码覆盖率。 What I have done is: 我所做的是:

  1. Created Metro application with some features. 创建具有一些功能的Metro应用程序。

  2. Created Unit Test Library (for Metro app) - in the same solution like my application (above). 创建单元测试库(适用于Metro应用程序) - 与我的应用程序(上面)相同的解决方案。

  3. Added one test class which contains few test methods. 添加了一个包含很少测试方法的测试类。

  4. To be able to compile test library I added link to class created in my application (Add->Existing item->Add as link". 为了能够编译测试库,我添加了在我的应用程序中创建的类的链接(Add-> Existing item-> Add as link“。

  5. Ran tests under VS - successfully. 在VS下进行测试 - 成功。

  6. Ran tests from console using vstest.console.exe - successfully. 使用vstest.console.exe从控制台进行测试 - 成功。

Now I have to calculate code coverage for my application. 现在我必须为我的应用程序计算代码覆盖率。 I knwo that vstest.console.exe has an option to enable code coverage but I use Express version of VS and that feature seems to be not available there. 我知道vstest.console.exe有一个启用代码覆盖的选项,但我使用的是VS的Express版本,那个功能似乎不可用。

The question is: How to use vstest.console.exe (or any other tool) to get right code coverage. 问题是:如何使用vstest.console.exe(或任何其他工具)来获得正确的代码覆盖率。 The tool takes appx of test library project so it calculates coverage for code from the library (mentioned single class from the application), right? 该工具采用测试库项目的appx,因此它计算了库中代码的覆盖范围(从应用程序中提到单个类),对吧? How tu use the tool to takes both library with test code and application with all code? tu如何使用该工具将带有测试代码和应用程​​序的库与所有代码一起使用?

Code coverage is available in premium and ultimate flavors of Visual Studio 2012 代码覆盖范围包括Visual Studio 2012的高级版和终极版

However please do note that we have not yet enabled code coverage for Windows Store apps as yet in VS 2012. 但请注意,我们尚未在VS 2012中启用Windows应用商店应用的代码覆盖率。

We use a tool OpenCover to perform the code coverage. 我们使用OpenCover工具来执行代码覆盖。 This outputs an xml coverage report of the results. 这将输出结果的xml覆盖率报告。 We then pass that xml file to ReportGenerator to create a nicely styled html report. 然后,我们将该xml文件传递给ReportGenerator,以创建一个样式很好的html报告。

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

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