Should I write unit test for everything?

前端 未结 13 1424
太阳男子
太阳男子 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:17

    The short answer is, No, but then that goes for everything in programming when you ask, "Should I X for everything?"

    The longer answer is you should at least consider it, which you are doing. Why can't you mock input into a sound recording class? Why not have the class bypass recording from a microphone to load audio from a file and have the output go to a file instead of a speaker. The test could compare the output result to the known correct result.

    For more on the philosophical side see this.

提交回复
热议问题