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?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Matt Whetton
  • 6,616
  • 5
  • 36
  • 57

3 Answers3

1

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

vissi
  • 2,325
  • 1
  • 19
  • 26
  • 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. – Matt Whetton Feb 22 '11 at 09:48
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.

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
habakuk
  • 2,712
  • 2
  • 28
  • 47