Running NUnit tests in Visual Studio 2010 with code coverage

前端 未结 5 1180
甜味超标
甜味超标 2021-02-01 19:20

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 thes

5条回答
  •  情话喂你
    2021-02-01 19:59

    You can get the VS 2010 code coverage functionality to work while running NUnit tests, but it's a hell of configuration work:

    Set up a generic test that runs the nunit-console-x86.exe like this:

    Does VS2010 Code Coverage support nUnit? (simplified description for xUnit)

    http://msdn.microsoft.com/en-us/library/ms182624(v=vs.100).aspx (general description)

    Make sure:

    • you have "instrument in place" activated. Trusting the deployment of VS won't work
    • you run nunit-console-x86.exe. The 64-Bit version won't work.
    • all libraries that need code coverage results are build into a single folder. Copying them (e.g. by build event) won't work. (For advanced: You can instrument the libraries in another location than their build output folder, but that's quite tricky.)
    • the folder with all libraries is working directory for the generic test and you start NUnit from it.
    • you provide the argument to NUnit as relative path to the working folder.
    • you additionally provide NUnit with the command line option /noshadow

    When you copy your dlls from different folders into a single folder for tests, strange things may happen. I for instance, got the reassurring result that almost all of the code for unit tests is coverred when running the unit tests. What a shame, that code coverage did not find the library tested by the unit tests!

    Well, after setting up all build output directories I ran into the strangest problem: From that folder NUnit does not run. I have it running from 2 separate locations, but here it goes "nunit-console-runner.dll not found".

    I only got it right with instrumenting the tested library at another location via:

    • tests > edit settings > local
    • Data and diagnostics > code coverage
    • deactivate the original location and add the library from the test folder

    Today it worked instantly, but the other day I tried to get the locations right for about an hour. I still don't know what I messed up that day.

提交回复
热议问题