Best practice for debug Asserts during Unit testing

后端 未结 12 2208
执笔经年
执笔经年 2020-12-23 02:35

Does heavy use of unit tests discourage the use of debug asserts? It seems like a debug assert firing in the code under test implies the unit test shouldn\'t exist or the d

12条回答
  •  Happy的楠姐
    2020-12-23 02:48

    Assertions in your code are (ought to be) statements to the reader that say "this condition should always be true at this point." Done with some discipline, they can be part of ensuring that the code is correct; most people use them as debug print statements. Unit Tests are code that demonstrates that your code correctly performs a particular test case; don'e well, they can both document the reuirements, and raise your confidence that the code is indeed correct.

    Get the difference? The program assertions help you make it correct, the unit tests help you develop someone else's confidence that the code is correct.

提交回复
热议问题