Reputation: 230
I'm trying to get code coverage working in VS2012 premium, and I'm having some trouble.
I have a C# solution with a few different projects, but most notably a Kernel.dll to be tested and a Kernel.Tests.dll that tests using NUnit and Rhino Mocks.
Using the NUnit Test Adapter (Beta 2), getting the tests into the test explorer works fine, as does running them. But when it comes to code coverage, I only get analysis from the test dll itself, not the code that is tested. This is when I do not use a .runsettings file.
I have also tried using a .runsettings file (like here: http://msdn.microsoft.com/en-us/library/jj159530.aspx) with this specification:
<Include>
<ModulePath>.*\.dll$</ModulePath>
</Include>
<Exclude>
<ModulePath>.*\.Tests\.dll$</ModulePath>
</Exclude>
but this just gives me an empty result, because now the test dll doesn't get included either.
The problem seems to be that it doesn't find the other parts of the solution, but I'm not sure where exactly it looks, or what I need to set up in order for it to be found.
Has anyone run into the same issue? Any ideas on how to fix it?
Upvotes: 6
Views: 4073
Reputation: 2299
I had the problem described in the question with standard MSTest tests. The instructions in the "Further Analysis" section of http://blogs.msdn.com/b/allendm/archive/2012/06/05/troubleshooting-missing-data-in-code-coverage-results.aspx provided more information about the problem:
In my case I saw a lot of reason="path_is_excluded" in the analysis.xml file. Apparently it's really easy to make VS think that you want to exclude a DLL. In theory, adding the wildcards in the section as described in the question should work. I got better results using the fully-qualified paths to the DLLs I wanted coverage for.
This sample .runsettings file came in handy: http://msdn.microsoft.com/en-us/library/jj159530.aspx#sample
Also, running tests from the command line first seemed to encourage the Visual Studio UI to do the right thing. In summary, it's not the easiest process to get working, but with CodeCoverage.exe at least you're not flying totally blind.
Upvotes: 0
Reputation: 580
This is not a problem with the NUnit test adapter but rather the Code Coverage capabilities in Visual Studio 2012 and TFS 2012. Decorate all of your test classes with the ExcludeFromCodeCoverage
attribute and the coverage calculator will reduce the noise.
See the blog Visual Studio 2012 RC – What’s new in Code Coverage and the MSDN article Customizing Code Coverage Analysis.
Upvotes: 0
Reputation: 312
It sounds like there may be an issue with the NUnit Test Adapter itself. I read on the Visual Studio Gallery Q&A section that they have already fixed bugs to do with the test adapter and debugging assemblies linked by the test assembly. This sounds related to me, so you may want to file a bug here: https://bugs.launchpad.net/nunit-vs-adapter/+filebug
Upvotes: 1