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.
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."
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.
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!
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!
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.