Dirty Tests and How to Clean Them
summary
Argues that test code deserves the same refactoring and review as production code and demonstrates it on a calculator API suite: converts duplicated setup into a beforeEach setup, extracts a API call wrapper holding RestTemplate and ObjectMapper, introduces a builder defaults pattern for test data, replaces magic literals with named constants, and renames tests for intent. Uses JUnit 5 and Spring test plumbing, keeps behavior identical (tests still pass) and warns static analyzers like SonarQube never replace human review.
AI-written summary · about
chapters (18)
- 0:00Clean test code mission
- 1:16Test code deserves clean standards
- 3:00Test code quality perception
- 7:18Investing in future efficiency
- 9:05Clean code definitions
- 10:32Key principles of clean tests
- 15:29Test code smells and anti-patterns
- 18:18Live demo: dirty Java tests
- 21:55Refactoring tests with setup and names
- 24:01Extracting common logic
- 26:55Using constants and builders
- 29:45Separating domain and platform
- 32:38Important versus replaceable values
- 34:32Refactoring without changing tests
- 36:19Reviewing tests like production code
- 37:26Q&A: parameterized tests and levels
- 40:35Static analysis and human review
- 45:16Closing remarks
related talks
54mDirty Tests And How To Clean Them
37mClean Test Code
43mUntangle Your Spaghetti Test Code
41mTesting done right: From bugs to brilliance
55mUnit Testing Like a Pro - Towards a Testable Design
54mAutomated Tests: What Courses Won't Teach You
47mFrom Bugs to Brilliance: Testing Toolbox in Action
02h 46mThe Joy of Testing
