Your test suite is making too many database calls!
summary
A one-line change to a single factory speeds a Rails test suite by 15%, because factories were silently creating large object trees. Profiling uses test logs, the factory bot active support notification, SQL-tracker or test-prof factory profiler to count queries and frequency, and simple object-graph diagrams to spot extra associations. Fixes are minimal base factories, inline test setup, avoiding callback-driven creates, and making associations explicit so the suite actually creates only the records needed.
AI-written summary · about
chapters (14)
- 0:00Intro
- 0:44Negative effects of slow tests
- 2:00The testing pyramid
- 2:27Avoid persisting data
- 5:40Locations
- 6:01Shared test setup
- 8:43Tests with wrong data
- 9:46Solution: Inline setup
- 15:04Minimal factory
- 18:26Broken data
- 19:04Updating in setup
- 22:09Profiling factories
- 23:54Diagramming
- 28:10Debugging techniques
related talks
09mSpeeding Up Your Test Suite
38mTake your slow tests to the doctor
02h 05mFrom slow to go: Rails test profiling hands-on
02h 05mFrom slow to go: Rails test profiling hands-on
41mHigh Cost Tests and High Value Tests
29m"Testing. Why so serious?"
42mHigh Cost Tests and High Value Tests
46mBetter code through boring(er) tests
