Easy, Breezy, Beautiful... Django Unit Tests with Colleen Dunlap
summary
Concrete techniques and outcomes, not abstractions: unit tests use Django.test.TestCase and setupTestData to speed runs, Factory Boy and Django model factories to generate realistic fixtures, and Django mock queries or mock.patch to avoid expensive DB work. Assertions include assertNumQueries to catch N+1s and assert_called_with to verify interactions. A grocery subscription case study shows submit/validate/charge/ship paths with payment and shipping APIs mocked, and examples demonstrate reproducible results and measurable speedups.
AI-written summary · about
chapters (17)
- 0:00Introduction
- 2:29What is a unit test
- 5:01Behavior vs implementation
- 7:32Mocking techniques
- 9:20Setup and teardown
- 11:49Factories for test data
- 14:19Django TestCase benefits
- 15:24Efficient test data setup
- 16:47Model Factory and signals
- 18:36Mocking queries
- 20:03Case study walkthrough
- 21:53Django assertions
- 24:00Serializer testing pitfalls
- 25:27Test decorators
- 27:11Test command options
- 29:02Extending TestCase
- 30:51Conclusion and key takeaways
related talks
24mPractical Unit Testing in Django
35mTurning test writing into a consistently brief and pleasant experience
49mKeynote - Testing in Django
29mSecrets of the testing masters
01h 06mEffective Django
41mTDD for APIs
53mDjango productivity tips and tricks
22mBDD (Behavior Driven Development) Testing for Django Apps
