Django 1.1 Testing and Debugging
I’ve been wanting to write this post for about four weeks now, and finally I have a chance to follow through on it. A little over a month ago I picked up Karen M. Tracey’s new book, by Packt Publishing. It’s been surprising to me that I’ve heard little in Django circles about this book because it fills a very nice space that has been a huge void in the Django world for some time. Testing within Django has always been something I’ve struggled with. The platform has never really “encouraged” testing in a way that I was used to in the Ruby on Rails or Pylons world. Likely this was more of an internal personal struggle of trying to figuring out how to fit testing within my workflow within the Django world than an actual shortcoming in the framework. For me, Ms. Tracey’s book was exactly what I needed to put things into perspective and to get clarity on an appropriate testing workflow in Django.
The book is very well written and quite readable. I found only a few minor code problems, and likely the result of chasing an ever evolving framework than actual oversight. I was able to digest the book over three days and began to put some of the teachings in the book into practice immediately.
The book starts off with some basic testing setup items and discusses testing approaches. Quickly Ms. Tracey moves into talking about doctests. Although I’m not a huge fan of doctests, I found the discussion easy to follow and Tracey does a great job of presenting the advantages and disadvantages of doctests. In chapter three Unit Tests using TestCase are covered and again Ms. Tracey does a very thorough job of covering the pros and cons of this approach. There were two areas of the book that probably helped fill in gaps for me the most, the chapter on using Client to do integration tests and the chapter on integrating third-party test tools. I still haven’t had a chance to dig into Twill but I definitely want to experiment in using Twill for my integration tests. The last half of the book is spent talking about debugging approaches and figuring out how to find and solve problems with your code. Although I personally didn’t get a lot of new information out of this section of the book, programmers new to Django / Python will find it to be an excellent resource in outlining the options that are available when things go wrong. The book finishes up with a chapter on moving your applications to production, debugging production problems, and load testing your applications.
I really only have two criticisms of the book and they are both minor. In chapter 5 where Ms. Tracey discusses integrating Django testing with third-party tools, I thought the book should have gone a little deeper. Coverage and Twill are covered in depth but not a lot of time is spent on using Nose as a test runner other than to provide the basic approach. I understand the book is not about extending Nose but it would have been nice to have a bit more to work with there. The only other criticism of the book was with the final chapter. Although there’s useful information in the “moving your app to production” chapter, it seemed out of scope for this book and a subject matter that is really deserving of an entire book itself. That said, I did enjoy the discussion on load testing and found it very helpful.
In summary, if you’re developing with Django this is another “must have” book in my opinion. There’s so much good information in this book, and it is presented in a very readable and easy to understand way. I’m planning to order a copy for each member of my team.