From: wsdng@... (=?ISO-8859-1?Q?Sascha_D=F6rdelmann?=) Date: 2003-09-04T21:45:40+09:00 Subject: Re: [OT] Unit Tests and Encapsulation Scott Thompson wrote: > The question I have, however, is one of style. Is this kind of class > extension often done in Unit Testing or is it more likely that the Unit > Test would only test the common public interface for the class. I think unit test should test at least the public interface but aren't bound to that. If you have a look at the history of the buzzword unit test, you might find out that it's one of those many Smalltalk "inventions" and Smalltalk doesn't have private interfaces. By convention you put all the private methods into a category called "private*" but Smalltalk doesn't enforce privacy. Ok, Ruby isn't Smalltalk but I strongly believe that in any language as dynamic as Ruby there are many ways to break encapsulation. You might consider to use one of them but I recommend that you solve those problems by choosing one of the following strategies instead: 1. Use patterns (bridge, strategy, etc...) to reduce the amount of privat methods. Move the private part of a class into a public part of a private class. 2. Use protected instead of private and subclassing to access those methods. That's what I do in C++. (Unit tests aren't bound to dynamic languages :-) 3. Don't use private at all. That's what I do in Ruby. I wouldn't mind if anybody showed me a more ruby like way ;-) Cheers Sascha