Rigor in capturing test cases for unit testing

后端 未结 5 1176
没有蜡笔的小新
没有蜡笔的小新 2021-02-09 14:02

Let\'s say we have a simple function defined in a pseudo language.

List SortNumbers(List unsorted, bool ascending);
5条回答
  •  终归单人心
    2021-02-09 14:46

    Don't waste too much time trying to think of every boundry condition. Your tests won't be able to catch every bug first time around. The idea is to have tests that are pretty good, and then each time a bug does surface, write a new test specifically for that bug so that you never hear from it again.

    Another note I want to make about code coverage tools. In a language like C# or Java where your have many get/set and similar methods, you should not be shooting for 100% coverage. That means you are wasting too much time writing tests for trivial code. You only want 100% coverage on your complex business logic. If your full codebase is closer to 70-80% coverage, you are doing a good job. If your code coverage tool allows multiple coverage metrics, the best one is 'block coverage' which measures coverage of 'basic blocks'. Other types are class and method coverage (which don't give you as much information) and line coverage (which is too fine grain).

提交回复
热议问题