This book is divided into two parts.
The first part is about Test-driven Development (TDD), a programming technique that will help you more reliable and easily modifiable software. I will first guide you through a very simple example in chapter 1, demonstrating how to use TDD to approach a project, and how to properly create tests from requirements. In chapter 2 I will then discuss unit testing from a more theoretical point of view, categorising functions and their tests. Chapter 3 will introduce mocks, a powerful tool that helps to test complex scenarios.
The second part introduces the clean architecture. The first chapter discusses briefly the components and the ideas behind this software structure, while chapter 2 runs through a concrete example of clean architecture for a very simple web service. Chapter 3 discusses error management and improvements to the Python code developed in the previous chapter. Finally, chapter 4 shows how to plug different database systems to the web service created previously
Table of Contents
-
- Introduction
- What is a software architecture?
- Why is it called “clean” architecture?
- Why Python?
- Acknowledgments
- About the book
- A brief history of this book
- How this book is structured
- Typographic conventions
- Why this book comes for free
- Submitting issues or patches
- About the author
- Setup a Python Project
- Virtual environments
- Python projects with Cookiecutter
- Introduction
- Part 1 - Tools
- Chapter 1 - Introduction to TDD
- Introduction
- A real-life example
- A simple TDD project
- Setup the project
- Requirements
- Step 1 - Adding two numbers
- Step 2 - Adding three numbers
- Step 3 - Adding multiple numbers
- Step 4 - Subtraction
- Step 5 - Multiplication
- Step 6 - Refactoring
- Step 7 - Division
- Step 8 - Testing exceptions
- Step 9 - A more complex set of requirements
- Recap of the TDD rules
- How many assertions?
- How to manage bugs or missing features
- Chapter 2 - On unit testing
- Introduction
- Tests should be fast
- Tests should be idempotent
- Tests should be isolated
- External systems
- Focus on messages
- The testing grid
- Conclusions
- Chapter 3 - Mocks
- Basic concepts
- First steps
- Simple return values
- Complex return values
- Asserting calls
- A simple example
- Patching
- The patching decorator
- Multiple patches
- Patching immutable objects
- Mocks and proper TDD
- A warning
- Recap
- Chapter 1 - Introduction to TDD
- Part 2 - The clean architecture
- Chapter 1 - Components of a clean architecture
- Layers and data flow
- Main layers
- APIs and shades of grey
- Chapter 2 - A basic example
- Project overview
- Project setup
- Domain models
- Serializers
- Use cases
- The storage system
- A command line interface
- HTTP API
- Conclusions
- Chapter 3 - Error management
- Introduction
- Basic requests and responses
- Requests and responses in a use case
- Request validation
- Responses and failures
- Error management in a use case
- Integrating external systems
- The HTTP server
- The repository
- Conclusions
- Chapter 4 - Database repositories
- Introduction
- A repository based on PostgreSQL
- A repository based on MongoDB
- Conclusions
- Chapter 1 - Components of a clean architecture
- Part 3 - Appendices
- Changelog
- Changelog
- Notes