Tips and Guideline for elegant Unit Test

Tips:

Consider for your test cases:

  • Positive cases
  • Negative cases
  • Boundary values
  • Combination of input values

General Guideline:

  • 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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容