Jump to ratings and reviews
Rate this book

Test-Driven Development with Python

Test-Driven Development with Python: Obey the Testing Goat - Using Django, Selenium, and JavaScript

Rate this book
By taking you through the development of a real web application from beginning to end, the second edition of this hands-on guide demonstrates the practical advantages of test-driven development (TDD) with Python. Youíll learn how to write and run tests before building each part of your app, and then develop the minimum amount of code required to pass those tests. The result? Clean code that works.

In the process, youíll learn the basics of Django, Selenium, Git, jQuery, and Mock, along with current web development techniques. If youíre ready to take your Python skills to the next level, this bookóupdated for Python 3.6óclearly demonstrates how TDD encourages simple designs and inspires confidence.

Dive into the TDD workflow, including the unit test/code cycle and refactoring Use unit tests for classes and functions, and functional tests for user interactions within the browser Learn when and how to use mock objects, and the pros and cons of isolated vs. integrated tests Test and automate your deployments with a staging server Apply tests to the third-party plugins you integrate into your site Run tests automatically by using a Continuous Integration environment Use TDD to build a REST API with a front-end Ajax interface

616 pages, Paperback

First published January 1, 2010

206 people are currently reading
1033 people want to read

About the author

Harry Percival

3 books64 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
192 (43%)
4 stars
163 (36%)
3 stars
68 (15%)
2 stars
13 (2%)
1 star
5 (1%)
Displaying 1 - 30 of 36 reviews
Profile Image for Matthew.
22 reviews3 followers
August 1, 2015
This is by far my favorite book on Django. In addition, it's probably one of the best written computer books I've read.

If you want to learn the Django syntax, read the Django documentation and go through the tutorial. Learning the syntax of a programming language or framework is the relatively easy part though. The harder part is learning how to efficiently and practically use the language/framework to create an actual application. That's where Harry Percival's Test-Driven Web Development with Python really shines.

Harry walks you through all the steps necessary to create, build, test, and deploy a Django website. Topics include:

- Using Selenium and Firefox for functional testing
- Creating unit tests
- Using Fabric to deploy code
- Authentication using Mozilla Persona
- Test fixtures
- Continuous integration

If you want to build a dynamic, database-backed website using Django, I heartily recommend buying Harry Percival's Test-Driven Web Development with Python.
Profile Image for Alireza Aghamohammadi.
52 reviews48 followers
November 13, 2021
یکی از بهترین کتاب هایی که در زمینه تست نرم‌افزار خواندم. کتاب قرار است با استفاده از فریمورک جنگو (چارچوبی برای برنامه نویسی تحت وب) یک سیستم ثبت کارهای روزانه توسعه دهد. روش آموزش کتاب مبتنی برای ایجاد تست‌-رانه است. ایجاد تست-رانه یکی از رویه‌های کاری معروف متدولوژی‌های چابک است که در آن قبل از اینکه کد نرم افزار نوشته شود، برای آن تست نوشته می‌شود. یکی از نکات جالب این کتاب این است که تا جای ممکن همه چیز را به صورت خودکار در می‌آورد تا در نهایت بتوانید تحویل مستمر داشته باشید. تحویل مستمر یعنی این که هر لحظه که تیم پروژه اراده کرد بتواند محصول توسعه داده شده را به دست مشتری برساند بدون آنکه زمانی برای کارهای عملیاتی صرف شود.
Profile Image for Matt Chan.
159 reviews5 followers
June 16, 2021
In terms of test-driven development the concepts are pretty well explained, I think because I came from a non-webdev perspective a lot of the practical stuff in the book re: Django isn't for me. Note that if you are TRYING to learn Django do NOT use this book because it's pretty obsolete and I've found the author would spend a lot of time talking about certain parts of Django but completely glosses over some more confusing but important concepts (like database migrations).

If you're like me and you're trying to get into TDD, this is a good book to skim and deep dive into the CONCEPTS of TDD, but I would recommend against what I did which is trying to implement all the code exercises/project in the book. Django is kind of a nightmare to debug, at least this older version of the framework the book uses.

The authors writing style is a little too cute for me, but that's a personal preference thing.
Profile Image for Anna Kabatova.
169 reviews2 followers
August 6, 2023
Я думаю, це важлива книжка, щоб дізнатись більше про TDD. Мені, зокрема, вона була важлива як частина розвитку в роботі. Але в плані нових знань я не знайшла для себе багато нового, бо все це вже знала. Натомість, книжка буде корисною, якщо ви ще незнайомі (або майже незнайомі) з фреймворком Django. Хоча, в сучасному світі більше використовується складніша версія - Django Rest Framework, про який автор говорить лише в додатку і не дуже багато, тож будьте до цього також готові.
Сама ідеологія TDD для мене трохи mind-blowing і здається трохи недолугим - ти пишеш 10 тестів, щоб змінити (написати) 1-2 рядки коду. Але, як і сказав автор, треба бути готовим, що внутрішньо ми будемо цьому противитись, бо вигода від TDD не "тут і зараз", а колись потім, в майбутньому, до чого також не всі готові.
Тим не менш, дізналась трохи цікавих ідей та підходів, тож, гадаю, книжка, зрештою, була корисна для розширення мого кругозору.
Profile Image for Case.
48 reviews15 followers
September 30, 2013
Once again I am tricked by the book title. This book would better find its target audience if it was titled Intro to Test-Driven Development with Selenium and Django. That has all the right keywords and would not mislead the reader into believing it serves a more general purpose than it does.

The writing is clever, however, and I have a singular appreciation for his git-centric tutorial approach. If you are looking for an intro to some subset of Selenium, TDD, Django, and Git, I think this will fit the bill nicely.

I would not recommend it for an experienced programmer though.
Profile Image for AcidGirl.
386 reviews
February 14, 2024
Nice, not too funny style, quite good didactically. Reasonably complex example. Sings the TDD gospel well.
Profile Image for Juan Argote.
3 reviews2 followers
January 9, 2016
This is an excellent introduction to the Test Driven Development programming paradigm. Harry manages to make this book accessible and entertaining while at the same time delving into the details of complex concepts. The text can also be used as an introduction to web development using the Django framework. If you are interested in developing tools the right way make sure to take a look at this book and obey the testing goat.
Profile Image for Roger Camargo.
7 reviews
July 7, 2013
Amazing book! you can learn also about good practices and many concepts!
Profile Image for Michael.
31 reviews
July 8, 2013
Read a rough cut, so it isn't quite finished, but it has a load of interesting approaches and ideas. Definitely a keeper.
Profile Image for Peter Augustinak.
121 reviews
June 2, 2023
I'm quite a fan of TDD approach and have been trying at least partly to use it in my own projects. I believe it can have real benefit for building simple, good designed code. I expected from this book to find some good tips&trick how to make it better. What I didn't expect was besides the obvious unit tests tool there will be also functional testing included in this pack, a this was very interesting.
Even though I consider very important that dedicated QA's are responsible for Functional/System Tests, this is giving quite a complex view also on this facet of testing part and can be very helpful for smaller teams or more simple projects.

The edition I was reading was a little bit out-dated but still, most of the discussed is valid. But as the book progressed farther, it started to be - at least from my point of view - a little bit chaotic, and Appendixes part maybe interesting, but not so much related.

Btw - not sure if intended, but the name "Internet Exploder" gave me quite a laugh reading in the train reading during my commute to work :)

41 reviews1 follower
October 10, 2022
This book is the killer intro/lay-of-the-land to those unsure about the whole TDD thing in python. Start here it will give you everything you need to go-go-go.

Starting around my first reading of this legendary "Goat" book I started dabbling in TDD. Now I like to say that I can't even remember how to write code not-TDD. How do people deal with the insecurity? How do you know your code works? Don't you have to write tests anyway?

Given away copies/recommended countless times to students and younger devs and they rant as enthusiastically as I do (if they actually read it).

This book has a permanent place on my bookshelf. Long live the goat book!

ps: also Harry is an amazing bloke overall.
4 reviews
April 5, 2020
Thanks to covid-19 which gave me the time to finish this book, after long time that this book was in my reading list!
I really enjoyed reading this book. I did know about unit tests and functional tests before reading this book and had written many unit tests for java projects. But this book shows many new aspects of testing. I specially liked the author's explanations from development level all the way to staging and production and how to make everything automated.
Obeying the testing goat is definitely hard but I learned to obey more in my future projects!
600 reviews11 followers
May 11, 2020
The book offers a good and detailed introduction into testing your Python code. The author explains tools that will make testing a lot simpler and shows in detail how you can test complicated tings like CSS well enough so that your tests find bugs and not your users. I do not use the same frameworks as the author; therefore, the last 200 pages got a bit boring. Nevertheless, this is a good book that offers a lot.
Profile Image for Constantine.
121 reviews2 followers
December 29, 2018
The best book I've ever read on programming and Django in particular! Even if it says "Test-Driven Development" you'll find so much more than that. Like application design, OOP practices, deployment and even CI! I always knew that tests are important but dreaded to try it. Now I can't wait to implement the knowledge I got from this book. It's a must read 100%!
Profile Image for Paul Schmidt.
152 reviews4 followers
January 22, 2021
Excellent introduction to Test-Driven Development, Web Frameworks, and Django! Worthwhile for the beginner programmer as well as the intermediate.

That said, it’s only after finishing that I realized how clear and easy-to-follow the Django docs are. Much of the content can be found there. (Although the philosophy of TDD is only briefly mentioned.)
Profile Image for Dan.
131 reviews
June 13, 2017
Truly excellent. The author doesn't just introduce Test Driven Development. He also includes a full demo of Django plus intros to Bootstrap, server setup, git-based deployments, and more.

I'm using this now to build a web application for my union and it's been very helpful.
2 reviews
September 3, 2017
Really good explanation of TDD. Some of the concepts and approaches I've carried to other languages. One thing though as somebody mentioned. It's quite focused on Django. But other than is quite transferable.
Profile Image for Son Dang.
2 reviews
May 17, 2019
Excellent books for web development and TDD beginner

The book strikes wonderful balance between theories and practical stuffs, a good sense of humour and coverage. Totally love it and will read it several times.
Profile Image for Steve.
125 reviews1 follower
April 5, 2018
Very much appreciated this step-by-step intro to TDD. Well-organized for learning from big picture through finer points.
Profile Image for Ivan.
223 reviews10 followers
December 29, 2018
Великолепное введение в TDD, море практики, отлично разьяснение.
Profile Image for Ramy Mohamed.
8 reviews6 followers
March 10, 2020
The book is awesome but TDD is too idealistic to be a practical way of building software.
Profile Image for Héctor Iván Patricio Moreno.
426 reviews22 followers
December 20, 2022
Este es un libro que si estás comenzando en Python y Testing es imperdible, es uno de los mejores libros técnicos que he leído, por su ritmo, profundidad, humor y manera entretenida y didáctica de escritura.

No leí toooodas las partes a profundidad, ya que es un libro muy práctico que tiene muchas partes de código (además de que está un poco desactualizado), pero creo que los principios que puedes aprender si trasladas el código a algo moderno, son muy valiosos.

Este libro cubre todas las partes de del testing, desde unit testing hasta behavior y pruebas de integración. No sólo te enseña a hacerlas, sino que además trata preguntas y puntos de vista diferentes, muchas veces evolucionando en los acercamientos a las soluciones.

Algo que tienes que saber es que usa Django para lograr muchas de las hace, por lo cuál muchas de las técnicas están estrechamente ligadas al Django del tiempo en el que se escribió y las soluciones que Django usa para hacer tests limpios, como por ejemplo, la creación y destrucción de la base de datos cada vez que se corre un ciclo de pruebas.

Sin duda, creo que este libro lo deberían leer todos los desarrolladores interesados en testing, o por lo menos echarle una lectura rápida (skimming) para ver en qué partes de las que profundiza te pueden servir tanto para empezar como aprender testing.

La última desventaja que le veo (en 2022) es su edad y que no usa herramientas de desarrollo y testing tan modernas como PyTest, pero creo que complementándolo con recursos que te las enseñen, se pueden aprender los conceptos de forma moderna. Espero haya una tercera edición actualizada pronto.

Profile Image for Chaitat.
68 reviews1 follower
June 5, 2017
I love this book so much. I read it 2 times already (different early release versions) as I am new to testing in general. It is worth every Baht I paid for to O'Reilly. Thanks to my friend who introduces this book to me and thanks to the author too. I will have to read it for the third time after I practice about the mocking. I got lost at that chapter. It is a difficult topic as the author said.
Profile Image for Pavel Karateev.
18 reviews5 followers
August 14, 2015
This is realy a great book, Harry is an outstanding professional and he used a simple language to describe a lot of testig topics and best practise. I definitely recommend it to anyone who works with Django and "web"-Python.

However there is a problem - Django is not mentioned in the title and it absolutely should. Short "Web" is not enough. If you know nothing about Django and you not a web developer you will lose a lot of time and maybe even fail to finish the book.
Profile Image for Anton Antonov.
350 reviews48 followers
November 25, 2015
A must read for every TDD enthusiast and Python and Django devs. It teaches you Django and JS testing and mocking. Yes, I said mocking. A real gem for TDD learning and understanding. Even if you practice TDD, you surely can learn something new along the way.

Also the Automation and Deployment parts were really useful even for experienced 'deployers'.
914 reviews4 followers
February 22, 2015
The integration of testing into a 'real' (simplified) python application fills a real hole on my bookshelves; too often testing is about work with a 'calculator' or similar toy program, or is shown in Java (which uses very different approaches in its testing).
Displaying 1 - 30 of 36 reviews

Can't find what you're looking for?

Get help and learn more about the design.