开发者

how to unit test AOP?

i'm using Unity to开发者_JAVA技巧 do AOP, could someone give me some idea how to unit test them?


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜