My apologies in advance for the terrible name - suggestions are welcome!
I read about DI and AOP, and I think I understand the main points; at least for the canonical example of adding a journal.
I would like to apply this to the test cases that we created in NUnit, for example. be able to automatically add an I / O log for all test case methods and any "helper methods" they call. (And I'm not attached to NUnit - if it's easier in other frameworks, please let me know.)
NOTE. This does not apply to the test object; I want to apply these methods to the test windows themselves.
It's pretty clear how to do this using PostSharp - this is their first example. However, I do not want to add my licensing processing to our project just for this experiment.
All the other links I found for AOP for C # are based on (dynamic) hooks provided by IoC container implementations like CastleWindsor, Unity, Spring.Net, ... All of them have a common problem in this case: you need A snippet of installation code that creates a proxy for the object to which you want to add interceptors. (I initially thought that this code would also have to create an IoC container, but I see that I'm wrong there.)
But I canโt see where this installation code will be used for nUnit test boxes.
The parameters I came up with and their problems:
- Create a testfixture class constructor for yourself. It will not work, due to recursion (the consumer asks for a thing, the thing is trying to return the proxy server to the thing, the proxy is trying to create the thing ... from reading https://stackoverflow.com/a/4646778/ )
- The role of my own reflection-based magic (which would be a big deal for me)
- the constructor wraps all the methods in the testfixture class and returns this wrapped object (not sure if it is possible for the constructor to do this)
- use the static constructor on testfixture to do this magic (assuming you can dynamically wrap class methods in place.)
- do something at the module level using the cctor module (via Einar Egilsson InjectModuleInitializer ) and wrap all the methods in all classes using the log.
- The simplest: some kind of factory for creating test module instances (NOT parameters for tests), from which I could use one of the IoC proxy generators
- For nUnit: the only tool I can find is to create a custom AddIn . Advantage - Cannot disrupt integration with ReSharper. Disadvantage - Deployment on all devs machines, especially on NUnit updates. Are there other ways to do this for nUnit?
- For MbUnit: it looks like it treats test indices as first-class values , and this is straightforward. Benefit: Easy deployment for all developers. Disadvantage: tests will not appear in Resharper. Note: how to deal with setup and shutdown .
Am I missing something in my options and conclusions?
Are there any easier ways to do this that I missed?
source share