Aspects
I have looked at Aspect-Oriented Programming (and AspectJ) before, and I’ve thought that it seems quite interesting, but also quite complicated. However, today I’ve read about one situation it seems to be really useful.
In an article at XProgramming.com called Virtual Mock Objects using AspectJ with JUNIT, Simon Monk and Stephen Hall is describing how AspectJ can be used to create virtual mock objects. With their “framework” (source code available here) you just have your test case class subclass their ComponentTestCase instead of JUnit’s TestCase. You can then create virtual mock objects by calling setMock(className, methodName, mockResult) (or a couple of alternatives). It’s that simple! You can then use assertCalled() and assertArgumentPassed() to make sure the virtual mock objects are used in a correct manner. (There are more features in there. Check out the article for more details, it’s a good read!)
I guess I have to look further into Aspect-Based Programming at some point. Perhaps when the AspectJ plug-in to Eclipse, called AJDT, is finished (it might be finished already, I’m not sure).
Zero comments