Thoughts and questions on Pragmatic Unit Testing
2 points stroke me when reading this “Pragmatic Unit Testing” book :
- in order to easily test some class, they suggest to open the required methods by making them protected. I had first to check that protected included package readability (it does) but still I think it’s going a bit too far : if the method was supposed to be private, package private is the nearest visibility which would fit. I would only make it protected if I intent to override it. Do I miss something ?
- the last paragraph is called “Testing invalid parameters”, and speaks of where to test the validity of the parameters. Their answer is “we find the easiest rule to adopt is the ‘keep the barbarians out at the gate” approach’, meaning internal components can trust the data they get. At work, we do it differently : every non private method has to check for the validity of its input (for which we have a dedicated assertion lib.). Would you suggest otherwise ?
++


No
the point is, that the gates are moving.
Took me some time to figure out the exact meaning of this sentence, but now I get it and yes, you’re darn right
Who knows which part of the code will be public in the future ?