Creating a Unit Test project is simple and documented many places so I won't duplicate that here. What I want to cover is what you need to do to a .Net Core project to enable Code Coverage results to be displayed. Code Coverage requires a classic Windows PDB file as opposed to the new format (click here for details of why a new format was created.) To do this you need to add the DebugType tag to the project with a value of Full
<DebugType>Full</DebugType>
This will cause the project to generate a classic Windows pdb so that the Code Coverage tools in Visual Studio will work correctly. It is often, almost always, useful to also create a runsettings file so that the test project doesn't display in the code coverage report and so that you can tweak it to only show your code. Details on creating a runsettings file, including a sample can be found here.
Lastly, there are a lot of posts on the internet about the evils of a full pdb in release mode (optimized) builds. This StackOverflow post incorrectly states that there is a performance impact in one of the comments. In Native code and in .Net Framework 4.0 and above and in .Net Core there is NO performance impact of creating a full pdb. Here is a Wintellect Post by John Robbins with the details. This Stack Overflow post sums the article up nicely, it is what led me to John Robbin's Post.
No comments:
Post a Comment