Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

13
  • I think this question would benefit from making it less abstract and extending it by some realistic example. What you described fits to so many different situations that there are also many different solutions, and whether it makes sense to duplicate all the testing logic, or none of it, or parts of it depends heavily on the specific case. Commented Jan 10 at 13:42
  • One set of tests should completely test the private functionality. If you have another public method calling the same private method, then you only need tests to cover the different public functionality for that second public method. Retesting the private method's functionality is not needed because that other set of tests are already covering it. Or, you could make the private method public and have separate tests for it and for each of the methods calling it. Commented Jan 10 at 14:16
  • 1
    ... but here @candied_orange's suggestion applies: one can write all tests only once but use them to trigger both method variants. Another case would be when you have two methods with different functionality, but sharing some private "tools". Here, the answers apply which say "focus on the contract, ignore that you know there is some shared functionaility", And there are also middle-ground cases, or (rare) cases where it can pay off to test the private methods directly. Commented Jan 10 at 15:34
  • 1
    This question is similar to: How do you unit test private methods?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Jan 10 at 16:31
  • 1
    @GregBurghardt better now? Commented Jan 10 at 18:06