Do you unit test private methods?

Encountered an interesting issue at work recently when it came to unit testing a new repo that was setup. The repo in question was relatively small and functioned as a basic cronjob, however in order to follow some best practices I decided to opt in for including some basic unit tests.

In doing so I mistakenly wrote a unit test for a private Python class signified with the standard underscore prefix! As I haven’t coded in Python in a while I had forgotten about this syntax, but I was a little stunned to hear from a colleague that best practice seems to be to purposefully not test private methods.

I’m curious to hear the thoughts from the Dev community on this one? I get by their very nature you should probably opt to test the Class that the method belongs to end to end rather than opt for a unit test, but what about when you’re looking for simple test functionality in a timely manner?

Curious to hear from the community on this one! (across different languages/frameworks too – not just Python)

原文链接:Do you unit test private methods?

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容