Should I write unit test for everything?

前端 未结 13 1422
太阳男子
太阳男子 2020-12-30 00:36

I am wondering should I write unit test for everything. There are some classes is very difficult to write unit test. For example, I am writing some program for handling audi

13条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-30 01:27

    Use unit testing where it makes sense - don't aim for 100% coverage. The main guideline is to think rather than applying either dogma or laziness.

    Having said that: If you have classes which are naturally hard to test, try to reduce how much they have to do. Isolate the untestable code and separate its API into an interface. Then test the logic which uses that API against a mock or stub.

提交回复
热议问题