About Unit Testing
Unit testing provides a structured and automated way of testing individual components of a system. As a methodology, unit testing has many advantages over manual, ad-hoc testing and debugging. Benefits which are easy to understand lists below,
- Because each unit test focuses specifically on an individual method, you can more easily determine the source of a failure for a failing unit test.
- Such a collection of tests is very useful for regression testing. As you implement new features, you can rerun existing tests to ensure that existing functionality has not been broken.
- Unit tests also serve as documentation for users of the methods under test. Developers can quickly review unit tests to determine exactly how particular components should be consumed.
One typical development flow segment of TDD is,
![2011040721013181.png](https://i-blog.csdnimg.cn/blog_migrate/c1c2ee0cf4a3a78c1378ce5bc11d1c54.png)
During this flow, practitioners also refer to the green state when all tests are passing and red state when some tests are failing. The little picture below depicts this little state machine.
DB unit testing just is reflecting of unit testing in database field. It has the same benefits as application unit testing.
Standard test case often is made of 4 sub-processes, including execute setup, run test, verify test result, execute teardown.
![2011040721020887.png](https://i-blog.csdnimg.cn/blog_migrate/8714bce745b571fa40c239df64253be7.png)