Unit testing Spring @Around AOP methods

后端 未结 1 1119
情歌与酒
情歌与酒 2020-12-13 00:19

I can unit test most of my Spring classes without needing to do Spring \"stuff\".

I can unit test @Before advice methods without using Spring too:

Example co

相关标签:
1条回答
  • 2020-12-13 00:50

    You can test a Spring Aspect by creating a proxy programatically:

    MyInterface target = new MyClass();
    AspectJProxyFactory factory = new AspectJProxyFactory(target);
    MyAspect aspect = new MyAspect(arg);
    factory.addAspect(aspect);
    MyInterface proxy = factory.getProxy();
    

    ... then you can call methods on proxy, and make assertions about aspect, proxy and target.

    0 讨论(0)
提交回复
热议问题