Ross Burton has a new article on subverting Java's access protection mechanism for purposes of unit testing. Its a very interesting article and I feel I could use it for a lot of my work. This has a nice side effect of being able to design a class "properly" and still be able to test it granularly without having to do some over design work. This is something Henri Yandell and I discussed awhile back. Right now I find that I am leaving a lot of fields/methods at package scope just so I can unit test things better. I am definitely going to be giving this a try.
As a next step, it would be interesting to fully implement out the PrivateAccessor class that he mentions and/or see this incorporated as a subclass of junit.framework.TestCase.
As an aside: From viewing Ross' site, it look like he submitted this article to IBM developerWorks sometime before Oct 10th, was rejected and then submitted it to O'Reilly. I hadn't realized that the turn around on O'Reilly articles was so long.

Comments (1)
I was originally planning on making PrivateAccessor a subclass of TestCase, but decided in the end that it is better being a fairly standalone class, in case someone is already using a subclass of TestCase.
Oh, and I originally sent the article to dW as I've written to them before. The turn around was very quick once the onjava editor, Daniel, had returned (I believe) from travelling. When contact was made there was about a week (maybe less) between my pre-first draft and the article appearing online, which is good.
# Posted by Ross Burton | July 24, 2004 1:49 PM