《Python測試驅動開發(fā)(影印版 英文版)》這本實用指南帶你從頭至尾經歷一個真實Web應用開發(fā)的全過程,展示了Python測試驅動開發(fā)(TDD)的優(yōu)越性。你將學到如何在應用程序各部分被構建出來之前就編寫并運行測試,然后開發(fā)*少量的代碼就讓這些測試運行通過。結果得到什么?能夠運行的簡潔代碼。
在書中,你將學到Diango、Selenium、git、iQuery和Mock的基礎知識,另外還有現(xiàn)代Web開發(fā)技巧。如果你準備將自己的Python技術提升到下一個層次,《Python測試驅動開發(fā)(影印版 英文版)》清楚地展示了測試驅動開發(fā)是如何提倡簡單設計并增進信心。
深入測試驅動開發(fā)工作流,包括單元測試/編碼周期循環(huán)和重構 為類和函數(shù)使用單元測試,并為瀏覽器內的用戶交互使用功能測試 學習何時與如何運用mock對象,以及單獨和集成測試的優(yōu)缺點 在開發(fā)用服務器上測試以及自動化部署 將測試運用到網站集成的第三方插件上去 使用一個持續(xù)集成環(huán)境來自動運行測試
Preface
Prerequisites and Assumptions
Companion Video
Acknowledgments
Part I. The Basics of TDD and Django
1. Getting Django Set Up Using a Functional Test
Obey the Testing Goat! Do Nothing Until You Have a Test
Getting Django Up and Running
Starting a Git Repository
2. Extending Our Functional Test Using the unittest Module
Using a Functional Test to Scope Out a Minimum Viable App
The Python Standard Library's unittest Module
Implicit waits
Commit
3. Testing a Simple Home Page with Unit Tests
Our First Django App, and Our First Unit Test
Unit Tests, and How They Differ from Functional Tests
Unit Testing in Django
Django's MVC, URLs, and View Functions
At Last! We Actually Write Some Application Code!
urls.py
Unit Testing a View
The Unit-Test/Code Cycle
4. What Are We Doing with All These Tests?
Programming Is like Pulling a Bucket of Water up from a Well
Using Selenium to Test User Interactions
The "Don't Test Constants" Rule, and Templates to the Rescue
Refactoring to Use a Template
On Refactoring
A Little More of Our Front Page
Recap: The TDD Process
S. Saving User Input
Wiring Up Our Form to Send a POST Request
Processing a POST Request on the Server
Passing Python Variables to Be Rendered in the Template
Three Strikes and Refactor
The Django ORM and Our First Model
Our First Database Migration
The Test Gets Surprisingly Far
A New Field Means a New Migration
Saving the POST to the Database
Redirect After a POST
Better Unit Testing Practice: Each Test Should Test One Thing
Rendering Items in the Template
Creating Our Production Database with migrate
6. Getting to the Minimum Viable Site
Ensuring Test Isolation in Functional Tests
Running lust the Unit Tests
Small Design When Necessary
YAGNI!
REST
Implementing the New Design Using TDD
Iterating Towards the New Design
Testing Views, Templates, and URLs Together with the Django Test Client
A New Test Class
A New URL
A New View Function
A Separate Template for Viewing Lists
Another URL and View for Adding List Items
A Test Class for New List Creation
A URL and View for New List Creation
Removing Now-Redundant Code and Tests
Pointing Our Forms at the New URL
Adjusting Our Models
A Foreign Key Relationship
Adjusting the Rest of the World to Our New Models
Each List Should Have Its Own URL
Capturing Parameters from URLs
Adjusting new_list to the New World
One More View to Handle Adding Items to an Existing List
Beware of Greedy Regular Expressions!
The Last New URL
The Last New View
But How to Use That URL in the Form?
A Final Refactor Using URL includes
Part II. Web Development Sine Qua Nons
7. Prettification: Layout and Styling, and What to Test About It
8. Testing Deployment Using a Staging Site.
9. Automating Deployment with Fabric
10. Input Validation and Test Organisation
11. A Simple Form
12. More Advanced Forms
13. Dipping Our Toes, Very Tentatively, into JavaScript
14. Deploying Our New Code
Part III. More Advanced Topics
15. User Authentication, Integrating Third-Party Plugins, and Mocking with JavaScript.
16. Server-Side Authentication and Mocking in Python
17. Test Fixtures, Logging, and Server-Side Debugging
18. Finishing "My Lists": Outside-In TDD
19. Test Isolation, and "Listening to Your Tests".
20. Continuous Inteoration (CI)
21. The Token Social Bit, the Page Pattern, and an Exercise for the Reader
22. Fast Tests, Slow Tests, and Hot Lava..
Obey the Testing Goat!
A. PythonAnywhere
B. Django Class-Based Views
C. Provisioning with Ansible
D. Testing Database Migrations
E. Behaviour-Driven Development (BDD)
F. Cheat Sheet
G. What to Do Next
H. Bibliography
Index