Tests Common
Table of Content
Test Smells
Before start removing some smell we need to estimate its benefits and cost
- Project Smells
- Production Bugs
- High Test Maintenance Cost
- 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
- Code Smells
- Conditional Test Logic
- Hard-to-Test Code
- Test Code Dublication
- Test Logic in Production
Goals of Test Automation
- Tests Should Help Us Improve Quality
- Tests as Specification
- Bug Repellent
- Defect Localization
- Tests Should Help Us Understand the SUT
- 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 …`
- Tests Should Be Easy to Run
- Fully Automated Test (without manual work, set database connection and etc)
- Self-Checking Test
- Repeatable Test
- Tests Should Be Easy to Write and Maintain
- Simple Tests
- Expressive Tests
- Separation of Concerns (e.g. test UI and buiseness logic separately)
- Tests Should Require Minimal Maintenance as the System Evolves Around Them
Philosophy
- Test first development
- Test by test
- create empty methods to have a specification
- implement one test at a time and then implement code to pass it
- Design outside-in
- think as a client
- sub dependencies on your way, then replace them with implementation
- State verification it’s preferable check test result.
- Design minimal test fixtures
Principles of Test Automation
- Write the Tests First
- Design for Testability
- Use the Front Door First
- Communicate Intent
- Don’t Modify the SUT
- Keep Tests Independent
- Isolate the SUT (stub all software that we do not control)
- Minimize Test Overlap
- Minimize Untestable Code
- Keep Test Logic Out of Production Code
- Verify One Condition per Test
- Test Concerns Separately
- Ensure Commensurate Effort and Responsibility