Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] AspectJ Unit Testing

manuel aldana wrote:
> i recently had the same problem to test an around advice, which i
> solved by using aspectj annotations to have access to aspect as a
> usual java class. then i used static dependency injection to mock
> dependencies. i used static fields and static setters for dependency
> injection because i could not figure out how to instantiate the aspect
> itself (maybe that is not possible for it is done behind the scenes by
> aspectj runtime).
Hi Manuel,
I'm relatively new to AOP and AspectJ, but IIRC it's possible to
instantiate an aspect using AspectClass.asAspect(). ICRR if this is
possible only for aspects declared as not singleton, of if also when an
aspect is a singleton (the default case) this static method will return
the default instance (but I think this is the case).

Using it you should not need to pollute your aspect with public static
stuff only for testing.


Back to the top