Link Details

Link 135896 thumbnail
User 285573 avatar

By alashcraft
via lostechies.com
Published: Nov 23 2008 / 18:33

You should only be testing public methods. Private methods are an implementation detail of the object and are subject to heavy change, etc. Any class, including test fixtures, that care about private methods on another object exhibit the “Inappropriate intimacy” code stench.
  • 15
  • 5
  • 1871
  • 338

Comments

Add your comment
User 211643 avatar

zynasis replied ago:

0 votes Vote down Vote up Reply

fits perfectly with bdd imo

User 285418 avatar

Motion Control replied ago:

0 votes Vote down Vote up Reply

How would you call a private method from outside the class anyway? (Don't tell me about reflection etc.)

User 282271 avatar

zone_reader replied ago:

0 votes Vote down Vote up Reply

Make it public but do not test it after that either :)

User 260224 avatar

chadmyers replied ago:

0 votes Vote down Vote up Reply

Yes, generally people use reflection to test the method. Sometimes they'll make it protected and create a test class that derives from the class-under-test in order to be able to call it. All in all, it's very smelly/hacky which should be everyone's first indication that this is not a good practice.

User 311881 avatar

stugots replied ago:

-4 votes [show comment] Vote down Vote up Reply
User 211643 avatar

zynasis replied ago:

0 votes Vote down Vote up Reply

so's ur face

User 260224 avatar

chadmyers replied ago:

0 votes Vote down Vote up Reply

For the Vote-downs, I'm curious why you voted this down. Can you please comment? Thanks!

User 210593 avatar

BlackWasp replied ago:

0 votes Vote down Vote up Reply

I have often wondered that. Shame Dzone doesn't force you to explainwhy you think something is bad.

User 311881 avatar

stugots replied ago:

-1 votes Vote down Vote up Reply

Maybe it's moronic?

User 260224 avatar

chadmyers replied ago:

0 votes Vote down Vote up Reply

Maybe what is moronic? Please elaborate.

User 211643 avatar

zynasis replied ago:

0 votes Vote down Vote up Reply

so's ur face
ZING!

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.