PostSharp and Visual Studio Code Coverage
Asked Answered
M

3

20

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 tests 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?

Megganmeggi answered 21/2, 2011 at 10:12 Comment(3)
this is one of the reasons I'm reluctant to do any IL weavingGittle
@AdamRalph, may be ignore code coverage report instead?Counterblast
@MichaelFreidgeim in my experience coverage reports make a valuable contribution to delivery. AOP is interesting, but I'm still waiting to face a situation where I'm convinced the ROI is worth it.Gittle
P
1

What code coverage tool do you use? In PartCover, you can ignore some classes or namespaces, like MyProgram.PostSharp.*, to receive correct numbers.

Paradies answered 21/2, 2011 at 16:32 Comment(1)
I'm using code coverage in VS2010 (not sure what its called - but basically the Microsoft one). I can put some exclusions in, but as the apsect code will appear in nearly everything, I cant do that. Thanks for the suggestion though.Megganmeggi
C
0

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.

Collincolline answered 10/4, 2011 at 21:21 Comment(0)
M
0

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
Myronmyrrh answered 14/3, 2012 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.