Subverting Java Access Protection for Unit Testing
Subject:   Unit Testing Private Fields and Methods
Date:   2003-11-13 11:46:11
From:   Trackback from anonymous2
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....