22 May 2007 - 18:38AOP and unit-testing
I think it is obvious, but I have not seen it mentioned anywhere: you need to test an application which has been AOP-ed (which has been built using AOP). Suppose that you wrote an advice that re-prices a shopping cart. You should unit-test the advice on its own, unit-test the application on its own, but you should also unit-test the advice applied to the application (just to make sure that the advice has been applied properly and is well integrated into the application). The application which has been enhanced by aspects is a brand new thing (well, maybe not) which needs to be unit-tested as well (especially if the advice is modifying its state as the shopping cart re-pricing advice does).
I wonder if you could/should compose unit-tests (let’s say JUnit tests) similar to the way you compose applications. The new unit-test (the one that tests the application as it has been modified by the advice) could probably be derived from the 2 unit-tests, it would be interesting to see if you could compose the new unit-test with the same ease with which you compose the application. One problem with unit-testing an AOP-enhanced application that I see is the difference between the ease of use with which an advice can be applied to a code-base and the ease of use with which you can create a unit-test which can test the new application. Very likely the advice is applied in configuration while the AOP test is written in code, there is a pretty big difference in the time spent on creating the new application vs the time spent on creating the tests for the new application. I wonder if testing platforms should not be tweaked in order to allow for unit test re-composition.
It would be interesting to know why nobody is talking about this. Could it be because AOP is being used mainly for infrastructure issues which do no inject significant behavior into the application (I see unit-testing AOP-enhanced applications being very important for weaving business-logic advices into an application)? Could it be because of the difference in the costs of creating an AOP-enhanced application and testing it? Once again, time will tell…
P.S. This post is pretty much a collection of various thoughts that I have about AOP and unit testing. I realize that it is not very well structured, but I didn’t have the time to dwell too much on it.
No Comments | Tags: AOP