Tips|Tips and Guideline for elegant Unit Test
Tips:
Consider for your test cases:
- Positive cases
- Negative cases
- Boundary values
- Combination of input values
- Do not use test/verify etc. in test names
- Test class name shall express the “given” or the “when” semantic
- Test method name shall represent the other parts of the test story
- Always name the code under test CUT
- Group tests in a test class by same setup or same code under test, e.g. method
- Test Methods tell a story:
- short and crisp in less than one screen
- in sections go Given - When - Then
- Test only the public interface, not private methods
- One test method tests one test aspect
- F.I.R.S.T paradigm:
- Fast - tests run quickly
- Independent - clearly isolated
- Repeatable - constant behavior
- Self-validating - pass or fail
- Timely - write tests with the product code
- Refactor tests at least as good as product code
- Consider design principles
- KISS - Keep it simple, stupid
- DRY - Don’t repeat yourself
推荐阅读
- android第三方框架(五)ButterKnife
- Android中的AES加密-下
- Eddy小文
- 带有Hilt的Android上的依赖注入
- android|android studio中ndk的使用
- Android事件传递源码分析
- RxJava|RxJava 在Android项目中的使用(一)
- Android7.0|Android7.0 第三方应用无法访问私有库
- 深入理解|深入理解 Android 9.0 Crash 机制(二)
- EditText默认不获取焦点弹出键盘