PostSharp and Visual Studio Code Coverage
I've recently started using PostSharp in some of my projects and have noticed an unfortunate side effect - the code coverage in all the projects its used with drops significantly.
I'm guessing the reason this happens is that the analyzer sees the PostSharp code and a lot of it isn't tested (i.e. boiler plate code for generic exception handling and logging). I could obviously write unit te开发者_C百科sts for every method that use the aspects, but if I'm honest it feels like a waste of time.
Has anybody got any experience with this kind of thing?
What code coverage tool do you use? In PartCover, you can ignore some classes or namespaces, like MyProgram.PostSharp.*, to receive correct numbers.
I am familiar with AOP but not specifically with PostSharp.
But...
If exclusion attributes do not solve the problem, the only alternative I see is building a version of the assembly without the code injected. How you are to obtain this depends on how PostSharp works. If it is done after the regular compile, you could make an extra build target that builds your assembly without PostSharp. Then you can use that in your unit tests. You should note that your unit test can no longer test the functionality added by PostSharp.
I found a solution for this problem:
If I don't add the aspect attribute in the debug mode, the code coverage is calculated right (if I run the tests in debug mode):
#If Not DEBUG Then
<Assembly: De.Trumpkin.LogWrapper.TraceLogAspect()>
#End If
精彩评论