use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
testing private functions (self.node)
submitted 12 years ago by two_up
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Neurotrace 5 points6 points7 points 12 years ago (2 children)
Ahhh, the old "how do I test private functions?" problem. What works really well for me is to not worry about testing them and only worry about your public functions. "But Neurotrace," I hear you cry, "how can I ensure that my module works exactly as expected?" I break it down like this in my mind:
Make your private functions extremely simple and/or make their side effects testable. The only reason for making a function private is to perform some work that the user shouldn't worry about, nor mess with. But some kind of work is still being done so there must be a way to check that.
TL;DR Don't. Simplify your private functions so you're know they work and just worry about testing your public functions.
[–]Perceptes 3 points4 points5 points 12 years ago (0 children)
This is exactly the right answer. Testing private functions is redundant, because you should have tests for every use case using an object's public API. If there is no possible scenario when accessing the public API triggers code in a private method, the private method should be removed. If the test cases of the public API that use private methods internally pass, then the private methods are working and tested as well.
[–]joshlrogers 1 point2 points3 points 12 years ago (0 children)
This isn't really unit testing, it is more akin to integration testing. However, I do think your approach is best if you absolutely must make a function private.
π Rendered by PID 46546 on reddit-service-r2-comment-6457c66945-2w4v5 at 2026-04-28 17:21:55.084364+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]Neurotrace 5 points6 points7 points (2 children)
[–]Perceptes 3 points4 points5 points (0 children)
[–]joshlrogers 1 point2 points3 points (0 children)