
面试碰到过这么个问题:啥是好的unittest,但是从来没正儿八经想过, 于是就跪了。
Definition
Unit testing is a software development process in which the smallest testable parts of an application, called units, are individually and independently scrutinized for proper operation.
Automatic: Invoking of tests as well as checking results for PASS/FAIL should be automatic
Thorough Coverage: Although bugs tend to cluster around certain regions in the code, ensure that you test all key paths and scenarios.. Use tools if you must to know untested regions
Repeatable: Tests should produce the same results each time.. every time. Tests should not rely on uncontrollable params.
Independent: Very important. Tests should test only one thing at a time.
Professional: In the long run you’ll have as much test code as production (if not more), therefore follow the same standard of good-design for your test code. Well factored methods-classes with intention-revealing names, No duplication, tests with good names, etc.
Readable : This can be considered part of Professional - however it can’t be stressed enough.
Reference: http://stackoverflow.com/questions/61400/what-makes-a-good-unit-test




近期评论