post Tools for testing static methods
talks about the subject of unit testing static methods.
In short, one wants to unit test ClassA, but ClassA uses some ClassB's static methods.
There, it was advice to wrap those static calls using interfaces and so on..
That is a good solution and sounds like good OO and the code looks pretty much like IoC. But what if you cannot do it. What if you have to call those methods statically (just because the client wants that way, and that's that!)?
Trying to figure out how could I unit test a ClassA, I started to think that I could try to change the system class loader. Such that when a request for ClassA's bytecodes was made, I could return the real ClassA, and when a request for ClassB was made, I could return a faked ClassB (compiled at runtime, for instance).
Does anyone has a clue if it is possible? I've seen that the java command has an "-Xbootclasspath" flag, but I think I doesn't help much.
Or someone has a better idea (but please, don't tell me to say dirty words to the client)?
[ EJFH: Fixed link ]
[ November 14, 2005: Message edited by: Ernest Friedman-Hill ]