Miscellaneous Debris

Avner Kashtan's Frustrations and Exultations
Conditional Publication

This is a nice trick I ran into when going over the sourcecode for the XML-RPC.NET library:

#if (DEBUG)
public
#endif
void Serialize(...)

This lets you run your unit tests when developing, but remember to set your methods to private when releasing.

Published Saturday, April 02, 2005 7:16 PM by AvnerK

Filed under: ,

Comments

# re: Conditional Publication@ Saturday, April 02, 2005 2:26 PM

Though it's looks ugly as hell. :)

Omer van Kloeten

# re: Conditional Publication@ Saturday, April 02, 2005 3:50 PM

Besides ugly, it's also dangerous.
Your units tests should test the same interface as the one exposed to client code. What's the point of testing methods not exposed to the client?
If there's some capability that the client code can't test, what is it doing in this class anyway?

Ori Folger

# re: Conditional Publication@ Sunday, April 03, 2005 4:57 AM

I'm not going to go into the whole "should you unit-test your private methods" argument, which is a long and painful one.
What I will say is that testing your private methods is a useful feature, even if you don't keep them around to your final tests. I certainly agree with the "you're not testing what you run" problem,

Avner Kashtan

Leave a Comment

(required) 
(required) 
(optional)
(required)