How do you make Testharp testable

Injection injection doesn't work in Postharp. How to make aspects verifiable? I really want to avoid creating concrete classes to enter my aspects.

I don't want these aspects to be done when I use unit testing techniques. If I'm testing the method, I don't want the logging aspect to kick in and try to create a specific logger during my tests.

I love Postsharp's idea and really want to use it, but these two problems seem to be giving me too many problems.

Any ideas?

+3


source to share


3 answers


This question is now covered in the PostSharp documentation:



http://doc.postsharp.net/postsharp-3.0/Content.aspx/PostSharp-3.0.chm/html/2ad6cf92-08eb-4537-a434-d88a3e493721.htm

0


source


For some third party tools like log4net, the configuration language is powerful enough that you can tweak (for example) the logging aspect in one way in your unit test project and another way in your real projects. So the logging aspect works even in your unit test, but actually can't do anything.



For other tools or your own custom solutions, you are better off programming the interface inside the aspect logic. Then, based on project-specific static config files or setup code, you can specify one implementation of your interface for production code and another for the project unit test (presumably a dead-end implementation that has no side effects, or better yet, write what would be for potential verification with a unit test).

0


source


Better yet, you can disable PostSharp in your unit test project using the MSBuild command. See this discussion .

0


source







All Articles