Xcode unit testing

前端 未结 4 1370
甜味超标
甜味超标 2020-12-02 23:56

I have never used Unit Testing and I understand the uses of it but I don\'t really know when and how to use it.

I would like to know when it\'s worth it to use Unit

4条回答
  •  执念已碎
    2020-12-03 00:20

    Write unit tests any time you write code that you'll have to maintain. That is, if you ever want to refactor anything — changing the code but keeping the behavior. Which is pretty much every bit of production code.

    The counterexample of "Hello, World" is not to bother with code you plan to throw away. A "spike solution" is just to figure out how you might approach a problem. Once you've figured it out, throw it away and start again. Only this time, you start with tests.

    Calling TDD "extremist" makes it sound irrational and impractical. In fact, once you learn TDD, it saves time/money.

    See Unit Testing Example with OCUnit for an example of how TDD works.

提交回复
热议问题