David Kahn wrote in post #978200:
> On Thu, Jan 27, 2011 at 8:39 PM, Marnen Laibow-Koser
> <li...@ruby-forum.com>wrote:
>
>>
>> Then you've got bigger problems.  You shouldn't be testing your private
>> methods; that's poking too deeply into an object's implementation.  You
>> should only ever test things that can be called from outside an object.
>>
>> If a private method is an intermediate value in a computation, just test
>> the end result.  If a private method really needs to be tested
>> separately, then it's telling you that it wants to be public.
>>
>
> I disagree -- for me public is what I want to expose to outside access,

And therefore it is the only thing that is worth testing.  No one cares 
what your private logic is like, because they never see it.

> regardless of complexity or size, where the private logic may actually
> be
> the most complex, being called by a relatively light public function.

Then test the return from the "light" public function, or make your 
private logic public.

> Now
> this may be a difference between TDD and BDD in pure forms, but for me I
> find if I drive my methods, public or private with test first, that the
> end
> resulting code is much more pliable.

No private method should have a test at all.  That's testing 
implementation, and therefore is bad.  You want to test interface only.

> Also, if I have coverage on what
> becomes complex private logic, at a more granular level -- then I have a
> much stronger project an also address minute issues closer to the
> source.

No!  All you have is brittle, implementation-dependent tests.  What you 
*think* is improving the quality of your code is actually hindering it.

> I
> am sure you have your method of working that works for you, this is what
> I
> have found effective and successful.

But it is neither.  This is a matter of principles, not taste.  Please 
do not handwave away what I am telling you by saying that it is a matter 
of taste -- these are principles you need to understand.  If you want to 
disagree after you understand the principles, I will be interested to 
hear your reasoning.

It is *ineffective* to test private methods because you never care about 
the return value from a private method as such -- if you cared about the 
return value, you'd have made the method public.

It is *unsuccessful* to test private methods because you are tying your 
tests too closely to implementation, which means they will fail if you 
change your implementation -- this despite the fact that one of the 
points of testing is to tell you that your code still works when you 
refactor your implementation.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to