Testing Private Methods

03-Jan-2019 2439
A question that has befuddled many developers, including myself for a long time, is: how do I test private methods? Should I test private methods?My opinion is no. I don’t test private methods. At least not directly. I test the behavior of a class’s private methods indirectly through the class’s public methods.The reasoning has to do with the reason why private methods exist. In my mind the value of private methods is that since a private method is hidden from the outside world I can feel free to refactor the private methods at any time and in any way, knowing that I’m not going to mess up any of the code that uses my class.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle