Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running NUnit tests in Visual Studio 2010 with code coverage

Tags:

We have recently upgraded from Visual Studio 2008 to Visual Studio 2010. As part of our code base, we have a very large set of NUnit tests. We would like to be able to run these unit tests within Visual Studio, but with code coverage enabled. We have ReSharper, so can run the tests within Visual Studio, but it does not allow the code coverage tool to do its thing and generate the coverage statistics.

Is there any way to make this work, or will we have to convert the tests over to MSTest?


EDIT: We've already tried the suggested tools:

  • TestDriven.Net
    This runs the NUnit tests fine within Visual Studio, and even works with the code coverage, but it also includes the tests as part of the covered assemblies. There doesn't seem to be a way to exclude the tests, but include the assembly being tested (our tests are in a different assembly from the code they test). We also don't really want to spend the additional £2000 it would cost us to get TestDriven.net for the whole team.

  • Gallio
    This didn't work. In order to get coverage output, the tests need to be run in the Visual Studio test runner. Gallio does not provide this support for NUnit.

Any further ideas? We did find a couple of open source attempts to get this type of thing working, but they are stale and haven't been touched for a long time (and therefore don't support VS2010).

like image 816
adrianbanks Avatar asked May 26 '10 12:05

adrianbanks


People also ask

How do I get NUnit code coverage?

You can add frameworks using the Extension Manager and automatically "Code coverage" starts working with installed framework. Code coverage is available only in Visual Studio Ultimate or Premium editions.

How do I test code coverage in Visual Studio?

On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.


1 Answers

The gallio automation framework is an open source project which should allow you to accomplish this. The site is at http://www.gallio.org/ There is initial VS2010 support in the last release with more work on it in the nightly builds.

There is more information on this here: http://weblogs.asp.net/astopford/archive/2010/04/13/gallio-and-vs2010.aspx

However, if you have money to spend on this take a look at http://TestDriven.Net

like image 156
Wolfwyrd Avatar answered Sep 18 '22 02:09

Wolfwyrd