Keep your Source Close and your Unit Tests Closer

后端 未结 7 467
既然无缘
既然无缘 2021-01-03 05:12

When I first started using unit tests I encountered two problems. First was being able to test private methods and fields and second falling behind on keeping unit tests up

相关标签:
7条回答
  • 2021-01-03 05:54

    You shouldn't test private methods separately, because they are (should be!) used from public methods or possibly constructors - so the public methods depends on the private ones to succeed with their assignments.

    These public methods/constructors will (should!) fail if the private methods don't do their work. So your approach is actually a bad approach for writing unit tests.

    And to iterate the previous answers - write your unit tests before you write your methods.

    0 讨论(0)
提交回复
热议问题