Does VS2010 Code Coverage support nUnit?

后端 未结 9 1930
情深已故
情深已故 2020-12-25 12:35

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

相关标签:
9条回答
  • 2020-12-25 13:18

    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.

    0 讨论(0)
  • 2020-12-25 13:18

    I tried every method I found on Google to enable that and then decided to give TestDriven.NET a try. It worked brilliantly: right-clik on the solution, test with coverage and done. Seriously, it couldn't be any easier.

    0 讨论(0)
  • 2020-12-25 13:21

    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).

    0 讨论(0)
  • 2020-12-25 13:22

    After fiddling with this for a little over an hour, I could not get it to work properly. I was able to get the generic test running properly with instrumentation for NUnit 2.5.5 using nunit-console.exe. Although the NUnit console runner ran my test successfully via the generic VSTest, I was never able to generate code coverage results.

    Although the test features of VS2010 sound great when reading about them, the implementation seems overly complex and very heavy. I've been using NUnit for years with great success and very low friction.

    I decided to try out JetBrains dotCover beta and within 5 minutes I downloaded it, installed it, and was able to configure and use it very successfully. It integrates seemlessly into ReSharper 5 and just worked for my NUnit tests. The code highlighting is a great visual tool to quickly locate blocks of code that were not executed by the tests.

    0 讨论(0)
  • 2020-12-25 13:24

    To my knowledge it doesn't. Our TestMatrix tool does though.

    0 讨论(0)
  • 2020-12-25 13:26

    I had the same problem and I found out a way to solve it. The project dll shown in "Code Coverage Detail" dialog is the wrong assembly to be instrumented and that's way is giving empty results. So you need to actually get that dll from another folder, it's in the unit test project folder! Since you added as a reference to your unit test project it will be there. So, for example, in my case I created a simple project calced Calculator and then created a unit test project called TestCalculator and added Calculator.dll as a reference in the unit test project. So in the "Code Coverage Detail" dialog I click on "Add Assembly" and I select Calculator.dll from the "..\TestCalculator\bin\Debug" folder. In that way it will work.

    0 讨论(0)
提交回复
热议问题