13

Is that possible to use Visual Studio Code Coverage without Unit Testing? I would like to make a coverage analysis within a normal program execution.

UPDATE:

There are no current solutions to use the Visual Studio Coverage tooling for what I want, although dotCover seems to be a nice third part solution for the problem.

Vinicius Rocha
  • 4,023
  • 4
  • 29
  • 38
  • If you can't do this using the tools provided there are 3rd party code coverage tools that would handle it ie [OpenCover](https://github.com/sawilde/opencover) - this SO question covers the options available to you http://stackoverflow.com/questions/276829/code-coverage-for-c-net – Shaun Wilde Feb 01 '12 at 21:56

2 Answers2

6

Here's a more detailed answer rather than just a link:

To do this for already instrumented files with an IIS Express application: Get the name of the site from C:\Users\<your user>\Documents\IISExpress\config\applicationhost.config

vsperfcmd /start:coverage /output:run.coverage

launch your app run your manual tests then to finish

vsperfcmd /shutdown

from related question https://stackoverflow.com/a/23791306/57883

for a full walk through, here's a link to the blog article I just posted on it:

http://imaginarydevelopment.blogspot.com/2015/02/get-code-coverage-from-vs-without.html

Community
  • 1
  • 1
Maslow
  • 18,464
  • 20
  • 106
  • 193
-3

I think you may be misunderstanding what Code Coverage is. Code Coverage indicates how much of your code is exercised by your unit tests. If you have no unit tests, you have zero code coverage. Are you perhaps referring to code profiling (measuring how long it takes for code units to execute?)

UPDATE:

If you're looking for metrics on what code is executed during normal execution, you want to do profiling. There are several profilers out there (eg Red Gate ANTS) or you can use your own homegrown solution. If your app is ASP.NET/ASP.NET MVC, You can also check out the MVC Mini Profiler made by the StackExchange team: http://code.google.com/p/mvc-mini-profiler/

NEW UPDATE
I'm confused by the comments. Code coverage is about unit testing.

From Wikipedia:

In computer science, code coverage is a measure used to describe the degree to which the source code of a program is tested by a particular test suite. A program with high code coverage has been more thoroughly tested and has a lower chance of containing software bugs than a program with low code coverage.

The title of the question asks how to "use Visual Studio Code Coverage without Unit Testing." There is no point in measuring code coverage if there are no unit tests.

Dave Swersky
  • 34,502
  • 9
  • 78
  • 118
  • If you want to see what percentage of your codebase is actually used during normal program execution, then this would be a useful metric to estimate how much "dead code" you have. – Eli Courtwright Feb 01 '12 at 18:48
  • 2
    Actually, I DO wanna know how much of my code is being covered during any kind of execution (eg. a manual testing execution). – Vinicius Rocha Feb 01 '12 at 18:49
  • 13
    Code Coverage is simply how much of your code is executed by whatever means you choose to execute it. If you choose to execute it by unit tests, fine, you can get code coverage. If you choose to exercise it manually, fine, you can get code coverage. If you choose to exercise it in production, fine. And there's no reason you can't combine all three of these with the right tools. See our family of test coverage tools: www.semanticdesigns.com/Products/TestCoverage for tools that do this just fine. – Ira Baxter Feb 29 '12 at 14:12