Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does VS2010 Code Coverage support nUnit?

Tags:

According to this schema VS2010 Premium and Ultimate has a tool for checking Code Coverage - together with a few other testing tools. Does this support nUnit too, or just MS test?

like image 304
stiank81 Avatar asked Apr 19 '10 07:04

stiank81


People also ask

Is NUnit a code coverage tool?

This is actually a code coverage utility tool developed specifically for Java.

How do I get NUnit code coverage?

Calculating code coverage You should now have a folder named "CodeCoverage" in the same folder where you executed the above command. OpenCover generates a file named "results. xml" which contains the code coverage information. This files contains a lot of information but isn't very readable.

Which plugin is used for getting code coverage for .NET projects?

JetBrains dotCover is a . NET unit test runner and code coverage tool that integrates with Visual Studio and JetBrains Rider. Make sure you know to what extent your code is covered with unit tests. dotCover calculates and reports statement-level code coverage in applications targeting .

How is code coverage measured in C#?

Code coverage is to determine to what portion of your project code is being tested by Unit testing; you can use the code coverage feature of Visual Studio. Code coverage is an option, when you run the test methods, using Test Explorer. On the Test menu, choose Analyze Code Coverage.


2 Answers

Visual Studio 2012 added support for third party unit test frameworks.

The test framework plugins available include:

  • NUnit
  • xUnit.net
  • MbUnit
  • QUnit
  • Jasmine

Adding support is very easy because you can add it from the Visual Studio Extension Manager.

For example you can add the "NUnit Test Adapter".

And now the "Analyze Code Coverage" works with third party unit framework. You can inspect all tests or only one.

And if your using VS 2010 don't be afraid to upgrade to VS2012 because sln files are compatibles (you need VS2010 with SP1).

like image 199
Be.St. Avatar answered Nov 04 '22 01:11

Be.St.


It's doable, but requires a bit of setup. I just got it working with xUnit. Presumably the below will work with NUnit too.

For this to work, you'll need three projects

  • The System Under Test -- SUT
  • A testing project using your favorite unit testing framework -- xUnitTest
  • A VS Test Project -- VSTest

    1. Create the VSTest project (breath easy)
    2. Delete the default UnitTest1.cs file
    3. Add a "Generic Test" to VSTest
    4. Specify the full path to the win32 version of the console runner for your testing framework, such as xunit.console.x86.exe
    5. Specify the full path to the xUnitTest dll
    6. Under the VS Test Menu->Edit Test Settings->Local->
    7. Data & Diagnostics "Tab"
    8. Make sure only Code Coverage is enabled
    9. Select Code Coverage row, then click the "Configure" button above (yes, this is a well designed UI :)
    10. In the "Code Coverage Detail" dialog
    11. Select both the dlls for SUT and xUnitTest
    12. Enable "Instrument assemblies in test"

Now when you run the VS2010 test, it'll correctly instrument the test dlls, run the code runner and gather the info into Visual Studio.

like image 29
Scott Weinstein Avatar answered Nov 04 '22 01:11

Scott Weinstein