Roi Shabtai
Roi Shabtai

Reputation: 3085

use visual studio code coverage as external tool

I would like to leverage visual studio code coverage ability out side Visual Studio as diagnostic test on environment without a Visual Studio instance on it.

I could not grab a tutorial or guideline on how it is done. So how it can be done? Even guidelines are good.

Upvotes: 0

Views: 537

Answers (1)

jessehouwing
jessehouwing

Reputation: 114822

In Visual Studio 2012 or newer you can use the vstest.console.exe to invoke tests to gather code coverage. the /enableCodeCoverage commandline switch enables it.

You can gather coverage from a commandline using the older vsperfcmd tool as well. This requires you to have at least a Visual Studio Test Agent installed on the machine. This is no full Visual Studio installation, but it contains teh components required to run tests and gather coverage details.

How to setup the VsPerfCmd tool can be found here in this MSDN post. I copied the steps:

I assume you want code coverage on MyApp.exe

  1. Open Visual studio command prompt

  2. Add %ProgramFiles%\Microsoft Visual Studio 10\Team Tools\Performance Tools to the path

    set path=%path%;'%ProgramFiles%\Microsoft Visual Studio 10\Team Tools\Performance Tools'

  3. CD to the folder that contains MyApp.exe

  4. Instrument MyApp.exe for coverage:

    vsinstr -coverage MyApp.exe

  5. Start the coverage monitor to collect code coverage data:

    vsperfcmd -start:coverage -output:MyApp.coverage

  6. Run the instrumented MyApp.exe:

    MyApp.exe

  7. Shut down the monitor once MyApp.exe is done:

    vsperfcmd -shutdown

  8. Open the MyApp.coverage file in Visual Studio

With the Test Agent installed on the machine, you can also trigger a test run from Visual Studio (even if it is installed on a different machine).

Upvotes: 1

Related Questions