Should I write unit test for everything?

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

    I tend to write tests as much as I can. Not only to prove that something works, but to make it obvious to someone else when they inevitably break it later.

    I've had a method that was 1 line long. In similar places in my app I had written unit tests, but being in a rush I thought that it could not possibly fail. I was wrong, it didn't work :-)

    The additional benefit of writing unit tests is not only to test your code, but so that someone who has never seen your code before can read the tests and understand how your code should work given specific scenarios...like a specification.

提交回复
热议问题