Tips|Tips and Guideline for elegant Unit Test

Tips:
Consider for your test cases:

  • Positive cases
  • Negative cases
  • Boundary values
  • Combination of input values
【Tips|Tips and Guideline for elegant Unit Test】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

    推荐阅读