How do you unit test private methods?

前端 未结 30 1847
无人及你
无人及你 2020-11-22 06:44

I\'m building a class library that will have some public & private methods. I want to be able to unit test the private methods (mostly while developing, but also it coul

30条回答
  •  执笔经年
    2020-11-22 07:33

    In my opinion you should only unit test your classe's public API.

    Making a method public, in order to unit test it, breaks encapsulation exposing implementation details.

    A good public API solves an immediate goal of the client code and solves that goal completely.

提交回复
热议问题