Hacker News new | past | comments | ask | show | jobs | submit login
A rewrite of the Django tutorial with Test Driven Development (github.com/hjwp)
67 points by rbanffy on Oct 7, 2011 | hide | past | favorite | 15 comments



This is cute, but not really realist. I.e. The test written before configuring the Django Admin.. how can you know what links you have to click if you don't see the page?


I agree that this example is a little confusing. The author is making assumptions about the behavior of the Django admin site based on either his previous experience using it, or the Django documentation. In practice it could be extremely difficult to write advance tests for third-party libraries, although I admit I don't have much experience doing this.

Normally I'd expect devs to write tests based on formal specifications of the desired program output (ha! more like a loose mental model). In these cases, all of the eventual behavior of the tested module will be controlled by code that the dev themselves wrote, which makes a much more compelling argument for TDD, but is also more difficult to convey in a made-for-newbies tutorial like this one.


The testing code looks horribly un-Pythonic to me, and I really don't think one should have to download a Java JAR to test a Python framework.


What doesn't look pythonic to you? Looks like he uses unittest for testing python and Selenium (java jar, certainly not required) for testing the frontend (html/js/rendering) in browser.


`javaStyleMethodNames` and using `self.assertSomething`. Despite its inclusion in the standard library, `unittest` is not a very Pythonic library (it comes from the days when most of the advanced portions of the stdlib was ported over from Java). Nose is slightly better and Attest[1] is the only one that I would really call "Pythonic."

[1]: http://packages.python.org/Attest/


Selenium requires java. There are python bindings to selenium-rc, but you still need the rc server. Normally I don't do selenium so early in the code process, but it isn't bad either.


Selenium 1.x does, but 2.x talks straight to the web browser via WebDriver. That may not be a technically accurate description of what's going on, but to the developer that's what it looks like. No Java server to start up.


Thank you. I've only worked on small projects and never truly forced myself to embrace tdd. I've always wondered why, if the Django core guys are so supportive of tdd, why it was not represented more in the original tutorial. I don't mean any disrespect, the tutorial is the best I've ever seen for such a framework and I realize they can't spoon feed us everything.


I don't recall hearing the Django guys espousing TDD. Testing - yes - but not especially a 'Tests firsts' approach.

I could be wrong but I wonder if you're conflating writing tests (everyone should do it) with TDD (a little more controversial)


In my opinion, this is one thing that the Rails folks have definitely got right. Testing is very important if your project is going to be of any size or if multiple people are working on it.

Testing with Django should probably be more transparent and definitely encouraged for beginners, and this is a great start!


Not just Rails, Ruby projects in general. Most have awesome test coverage.


THANK YOU for posting this! I always had to figure out how to test my code AFTER the fact when reading Django documentation. This makes it much easier to write good code. Thanks!


This is awesome! I think more tutorials should be written this way. ;-)


For other python web developers, what front end test tools do you other than selenium? Anything better out there?


Check out Sikuli, it does pattern matching on images with a bit of OCR thrown in. It has its own quirks and isn't nearly as mature as Selenium but is neat because it doesn't care at all about the underlying layout of a page.

http://sikuli.org/




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: