Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to unit test AOP?

i'm using Unity to do AOP, could someone give me some idea how to unit test them?

like image 593
user192415 Avatar asked Feb 03 '26 09:02

user192415


1 Answers

Does your "aspect" implementation is a class that implements ICallHandler (or very similar IInterceptionBehavior in Unity 2.0) and is already added to intercepted object's execution pipeline?

If so, you can test it separately quite ordinarily. What you test is Invoke method - call it with mock created for IMethodInvocation, set up to have your object's state before invoking the aspect and with GetNextHandlerDelegate to mock object set up to represent your intercepted object call.

You can then assert:

  • on your delegate target if proper calls are made - i.e. test whether the aspect breks/doesn't break the execution properly, whether the call arguments were properly altered etc.
  • on Invoke's result (IMethodReturn object) - i.e. test whether the return result was properly altered, whether the exception was thrown etc.
like image 197
NOtherDev Avatar answered Feb 05 '26 01:02

NOtherDev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!