ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Subverting Java Access Protection for Unit Testing
Subject:   Alternatives to reflection
Date:   2003-11-14 01:56:04
From:   anonymous2
I have variously used two other approaches to get around the problem of testing private fields/methods:


1. Use static innner classes. These have access to the private fiels/methods of the enclosing class. The restriciton is that they can only access the private variables of one class. However, you can build public "communication" methods into them. These are methods that expose private date of the outer class and are intended for use by other classes that perform tests.


2. Logging. It's a good idea to add logging to an applicaiton anyway. Sometimes I perform a test and check the result of a log (where private variable content appears) to determine success/failure.


1 to 1 of 1
  1. Alternatives to reflection
    2003-11-14 06:15:01  anonymous2 [View]

1 to 1 of 1