Is unit testing private methods a good practice?

后端 未结 4 2040
青春惊慌失措
青春惊慌失措 2020-12-09 19:03

I am wondering if unit testing private methods is a good practice?

Normally only public interface should be tested.

However, I have found out that during com

4条回答
  •  粉色の甜心
    2020-12-09 19:45

    IMHO it's a very good idea, I do it all the times. I usually create a helper class which makes the private methods accessable and test it..

    Usually it's even easier to test private methods, since they do something very specific. On the other hand you might have a big public method which is a bit harder to test. So it certainly simplifies unit tests.

提交回复
热议问题