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.

8
  • 2
    Check this question on StackOverflow. A couple of techniques are mentioned and discussed. What's the best way of unit testing private methods?
    – Chiron
    Commented Aug 14, 2011 at 5:02
  • 45
    My opinion has always been that private methods don't need testing as you should be testing what is available. A public method. If you can't break the public method does it really matter what the private methods are doing?
    – Rig
    Commented Apr 12, 2012 at 18:22
  • 3
    Both public and private methods should be tested. Hence, a test driver generally needs to be inside the class it tests. like this. Commented May 28, 2015 at 10:08
  • 3
    @Rig -- +1 -- you should be able to invoke all the required behavior of a private method from your public methods -- if you cannot then the functionality can never be invoked anyway so there is no point in testing it. Commented May 28, 2015 at 10:40
  • 1
    This article was useful for me enterprisecraftsmanship.com/posts/unit-testing-private-methods
    – frederj
    Commented Feb 24, 2020 at 18:28