ruby on rails - Not testing public methods -


general advice i've seen regarding tdd books such poodr not test private methods. idea public methods call private methods tested , should enough verify private methods.

this makes sense cases private methods several "layers" deep? here's contrived example of mean:

public  # test method def foo   private1 end  private  def private1   private2 end  def private2   private3 end  def private3   # stuff end 

i don't have real world example share in cases this, still enough test public method foo? or code constructed pointing possibly deeper problem?

the idea behind internals of class implementation details of class.

your contrived example exposes output foo user. that's thing tests have make sure doesn't change.

if dry whole class 10 methods foo use 1 method internally wouldn't want see tests break because changed privates. long public interface still works there no need test internals.

the principle behind encapsulation. don't care class under covers - concerned can run on quantum computer , send it's data stream man on moon calculation - long output correct users see correct , expected result.

any attempt test privates lead tests break once change these methods. that's fine in lot of cases, over-testing makes spend far more time fixing broken tests being productive, rule there give wiggle-room.

of course advice depends: if feel it's important 1 method works might want write tests it. tests duplication of tests had in place public methods anyway.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -