notes

Tests Common

Table of Content

Test Smells

Before start removing some smell we need to estimate its benefits and cost

  1. Project Smells
    • Production Bugs
    • High Test Maintenance Cost
  2. Behaviour Smells
    • Fragile Tests
      • Interface Sensitivity - tests sensetive to changes in sut interface
      • Behavior Sensitivity - tests sensetive to changes into sut behavior
      • Data Sensetivity - tests sensetive to changes in data schema
      • Context Sensitivity - when tests depend on environment
    • Non-Determinism in Tests
    • Slow tests
  3. Code Smells
    • Conditional Test Logic
    • Hard-to-Test Code
    • Test Code Dublication
    • Test Logic in Production

Goals of Test Automation

  1. Tests Should Help Us Improve Quality
    • Tests as Specification
    • Bug Repellent
    • Defect Localization
  2. Tests Should Help Us Understand the SUT
    • Tests as Documentation
  3. Tests Should Reduce (and Not Introduce) Risk
    • Tests as Safety Net
    • Do No Harm (do not modify production code)
      • a lot of mocks creates an illusion that system works, but actually it could be broken
      • if “prod” then …`
  4. Tests Should Be Easy to Run
    • Fully Automated Test (without manual work, set database connection and etc)
    • Self-Checking Test
    • Repeatable Test
  5. Tests Should Be Easy to Write and Maintain
    • Simple Tests
    • Expressive Tests
    • Separation of Concerns (e.g. test UI and buiseness logic separately)
  6. Tests Should Require Minimal Maintenance as the System Evolves Around Them
    • Robust Test

Philosophy

  1. Test first development
  2. Test by test
    • create empty methods to have a specification
    • implement one test at a time and then implement code to pass it
  3. Design outside-in
    • think as a client
    • sub dependencies on your way, then replace them with implementation
  4. State verification it’s preferable check test result.
  5. Design minimal test fixtures

Principles of Test Automation

  1. Write the Tests First
  2. Design for Testability
  3. Use the Front Door First
  4. Communicate Intent
  5. Don’t Modify the SUT
  6. Keep Tests Independent
  7. Isolate the SUT (stub all software that we do not control)
  8. Minimize Test Overlap
  9. Minimize Untestable Code
  10. Keep Test Logic Out of Production Code
  11. Verify One Condition per Test
  12. Test Concerns Separately
  13. Ensure Commensurate Effort and Responsibility