How to unit test AOP?

I am using Unity to create AOP, can someone give me some idea on how to unit test them?

+3
source share
1 answer

Does your implementation implement an “aspect” class that implements ICallHandler(or is very similar IInterceptionBehaviorin Unity 2.0) and already added to the execution pipeline of intercepted objects?

If so, you can test it separately. What you are testing is a method Invoke- to call it using the mock created for IMethodInvocation, configure its state of the object before calling the aspect, and using GetNextHandlerDelegateto trick the object configured to represent your intercepted call to the object.

Then you can state:

  • on your delegate’s target if calls are invoked - i.e. check whether the breks / aspect does not break the correct execution, whether the call arguments were changed correctly, etc.
  • on Invokeresult ( IMethodReturn object), that is, check whether the return result was correctly changed, whether an exception was thrown, etc.
+1
source

Source: https://habr.com/ru/post/1744092/


All Articles