DISQUS

DISQUS Hello! Virtuous Code is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Jump to original thread »
Author

Testing Private Methods

Started by avdi · 8 months ago

Periodically the question of how to test private methods comes up at work or online. My answer is: don’t. It may seem trite, but there is some reasoning behind it.

Private methods are, by definition, implementation details. If you are approaching your tests from a b ... Continue reading »

5 comments

  • I'm glad to have at least provided a little bit inspiration for this blog post. We totally see eye-to-eye on this matter.
  • Couldn't agree more. I often hear questions about testing private methods and to me it makes no sense whatsoever. As you say: private methods are an implementation detail!
  • Or the `slugify` method could be turned into a function, since it isn't really relevant to the `BlogPost` instance.
  • Ruby doesn't really support the notion of free functions (it kind of fakes it, but in a way I prefer not to take advantage of in anything but quick one-off scripts). It could be a class-level method, I suppose. I still prefer the class approach, because then if you decide to mock the slugification out you're not mocking methods on the class under test.
  • Nice writeup. I agree with breaking out the code into separate classes here.

Add New Comment

Returning? Login