The Book (original) (raw)
"Test-Driven Web Development with Python" aims to teach TDD for web programming. It uses a concrete example -- the development of a website, from scratch -- to explain the TDD metholology and how it applies to building web applications. It covers the Selenium browser-automation tool, unit testing, mocking, and interacting with Web technologies from the basics of static content, database integration, throught the inescapable JavaScript, and onto more advanced (and trendy) topics like NoSQL, websockets and Async programming.
Reading it
There are lots of ways you can read this book:
Obviously these are my favourite options! O'Reilly have been great, they deserve your support, and although I only get a small amount in royalties (about a dollar per sale if you're curious), it still pays for the occasional dinner out every month which I appreciate. Plus, real physical books are nice...
TIP: I don't recommend you use Google Play Books, or at least not their PDF version, it's horrible
Or read it here for free
Help yourself! It's all free and CC-licenced (thanks O'Reilly!). I see this as a "try-before-you-buy" scheme, and I hope that if you enjoy it you'll buy a copy -- if not for yourself, then perhaps for a friend!
Table of contents follows:
Introduction:
- Praise for Test-Driven Development with Python
- Preface
- Preface to the Third Edition: TDD in the age of AI
- Prerequisites and Assumptions
- Companion Video
- Acknowledgments
Part 1: The Basics of TDD and Django
- Chapter 1: Getting Django Set Up Using a Functional Test
- Chapter 2: Extending Our Functional Test Using the unittest Module
- Chapter 3: Testing a Simple Home Page with Unit Tests
- Chapter 4: What Are We Doing with All These Tests? (And, Refactoring)
- Chapter 5: Saving User Input: Testing the Database
- Chapter 6: Improving Functional Tests: Ensuring Isolation and Removing Voodoo Sleeps
- Chapter 7: Working Incrementally
- Chapter 8: Prettification: Layout and Styling, and What to Test About It
Part 2: Going To Production
- Chapter 9: Containerization aka Docker
- Chapter 10: Making Our App Production-Ready
- Chapter 11: Getting A Server Ready For Deployment
- Chapter 12: Infrastructure As Code: Automated Deployments With Ansible
Part 3: Forms and Validation
- Chapter 13: Splitting Our Tests into Multiple Files, and a Generic Wait Helper
- Chapter 14: Validation at the Database Layer
- Chapter 15: A Simple Form
- Chapter 16: More Advanced Forms
Part 4: More Advanced Topics in Testing
- Chapter 17: A Gentle Excursion Into JavaScript
- Chapter 18: Deploying Our New Code
- Chapter 19: User Authentication, Spiking, and De-Spiking
- Chapter 20: Using Mocks to Test External Dependencies
- Chapter 21: Using Mocks for Test Isolation
- Chapter 22: Test Fixtures and a Decorator for Explicit Waits
- Chapter 23: Debugging And Testing Server Issues
- Chapter 24: Finishing "My Lists": Outside-In TDD
- Chapter 25: CI: Continuous Integration
- Chapter 26: The Token Social Bit, the Page Pattern, and an Exercise for the Reader
- Chapter 27: Fast Tests, Slow Tests, and Hot Lava
Epilogue: Obey the Testing Goat!
Appendices
- Appendix A: The Subtleties of Functionally Testing External Dependencies
- Appendix B: Continuous Deployment (CD)
- Appendix C: Behaviour-Driven Development (BDD) Tools
- Appendix D: Test Isolation, and "Listening to Your Tests"
- Appendix E: Building a REST API: JSON, Ajax, and Mocking with JavaScript
- Appendix F: Cheat Sheet
- Appendix G: What to Do Next
- Appendix H: Source Code Examples
- Bibliography
How to comment or get in touch
I am far from the ultimate authority on TDD, and I'm always interested in talking about TDD, so do get in touch.
There's a comment system here for each individual chapter, so feel free to use that.
If you'd like to fix a typo, you can open a Pull Request at https://github.com/hjwp/Book-TDD-Web-Dev-Python/pulls
If you'd like to have a more philosophical discussion, or talk about anything Python or TDD-related, you can get in touch with me directly via
I look forward to hearing from you.