Unit test – Best practices
1. Keep test method as simple as possible:
- DRY principle (Don't repeat yourself)
- Re-use test set up across test cases: put non-trivial test data in test set up method
- Clean test code as productive code
2. Evident data
3. All non-trivial methods must be passed unit test with 100% coverage ratio.
4. Unit test independent with:
- Other unit tests, order of unit test running
- Environment (operating system, hardware configuration, database …)
5. Fix broken test as soon as possible (it should be immediately)
6. After fixing defect, write unit test to prevent it re-occurs
7. All test cases must be passed at the end of working day
8. Test project code, not library code
9. Minimal maintenance of test code
10. If you can not write unit test for some functionality that means your code has problem! Refactor it immediately
Hey great interesting, bonus for this post.