Dela via


Code Coverage result from ASP.Net project

One thing that I love from Visual Studio 2005 unit testing is the code coverage result.

Obtaining code coverage result for ASP.Net projects it little bit tricky. From my experience, the requirements are:

  • IIS must be in the same box where you run your test assemblies.
  • You have to be the admin on that box, or if you are not, the web project must run with the same identity with you.
  • If you are using Remote Desktop to work on your server, make sure you are connected in the console mode (command line: mstsc /console /v:YourServerName)

To setup your test project to generate code, open your solution, click File>Add>Existing Web Site, select localhost, and add your site from there.

After your site is added, open the test run configuration, select Code Coverage option, and you will be able to see your ASP.Net project there, check the checkbox, and your test will generate code coverage result.

What will happen if you add a remote site instead of local site? You can add remote site only if the remote site has FrontPage Server extension installed and configured, but still, unless you are running the test in the same box with the IIS, you will not get the code coverage result.