

Test-Driven Django Tutorial - eddie_the_head
http://www.tdd-django-tutorial.com/

======
zacharyvoase
+1 from me. We need more language and framework tutorials to be written with
testing in mind. I wouldn't be surprised if the work from this was moved into
Django's official documentation very soon.

------
ikawe
Hooray for more guides on testing in python! Although there are a lot of
mostly-equivalent tools to what I've grown to love in Ruby-land, I think the
most lacking thing might be a sense of arbitrary "best practice".

The zen of python states "There should be one, and preferably only one, way to
do it", which I see at the level of a line of code; However, at a higher
level, I always feel like there are dozens of ways to pattern something, and
none with any particular community buy-in. This leaves my integration
balancing awkwardly across several different authors ideas of how things
should work.

What can we do about it - How can we make the python community more
opinionated? The desired end result is that software is less surprising, that
common problems have a readily accessibly, highly compatible solution.

Maybe we need more snobs in Python? ;)

------
numlocked
Unfortunately the first thing that jumped to mind when clicking through was
this: <http://grokcode.com/746/dear-python-why-are-you-so-ugly/>

I realize it's a almost self-consciously ugly and it's a development tutorial,
but still - a little CSS & typography goes a long way.

~~~
kvnn
What about the typography needs improvement? In my opinion, it is very
readable.

There are is no window decoration, and I'm fine with that.

~~~
ralphsaunders
The lines are far too long, it would certainly benefit from more leading,
larger sizing would be nice, and a typeface with a larger x-height (times is
so tiny), would greatly improve readability.

~~~
hjwp3
thanks for the feedback - am not mad good at the old graphic design, but it's
all too easy to just say "I can't be bothered with that stuff"... I'll try and
make some improvements. I gather it looks particularly ugly on windows, must
take a look...

~~~
hjwp3
have started by fixing a windows fallback font for the text so that it's not
Times!

------
leetrout
That is a great resource. Especially pulling Selenium into the picture and
showing good functional testing. Thanks to the author for putting this
together.

While I understand the need to show how unit tests work do we really need to
test Django's ability to save records to the database and retrieve them in
part 1? I personally don't follow true TDD, especially with model fields. Am I
off in left field? Is this pattern common with other developers? Or perhaps
people test for a fields existence by checking _meta.fields?

The example of testing a specific attribute, verbose_name, (that is expected
to be altered by the user) in part 2 and the user implemented __unicode__
method test I do think is a great example, though.

I like Daniel's summary in the "What To Test?" section at
[http://toastdriven.com/blog/2011/apr/10/guide-to-testing-
in-...](http://toastdriven.com/blog/2011/apr/10/guide-to-testing-in-django/)

~~~
hjwp3
Also, I'd tend to agree that testing model attributes is a bit OTT - it's very
close to testing a constant... but, it really doesn't take that long, and if
it provides a scaffold that makes it easier to write future unit tests on the
model (eg, on a computed field), so much the better for a little nudge that
encourages more test coverage...

------
jayliew
I'm a Django guy who started picking up some Rails out of curiosity, and
that's when I realized how great TDD, specifically, automating behavior-driven
testing is in general .. and I was wondering why it didn't seem like a
prominent thing in the Django community. Thanks for doing this, please do
continue!

~~~
teilo
I disagree. I rarely find Django apps without accompanying tests. No
submissions to Django proper ever make it in without tests. But as to no test-
based tutorial - you're right, but most tutorials in any given language cover
testing only after the language is learned, so that's hardly unique to Django.
I hope this changes, of course. Everyone should test.

~~~
jayliew
I'm not referring to "it's good practice to test your code". I mean, TDD aka.
writing tests to fail, then writing code to make the tests pass. Specifically,
behavior driven testing, not just TDD.

------
mattdeboard
A couple of great tutorials on testing in Django is
<http://toastdriven.com/blog/2011/apr/>.

------
kvnn
I've been wanting to do TDD for my newest project, and hadn't searched for
docs yet. Thank you, I'm using this now.

Using the core Django tutorial was a great decision. Being able to recycle
things that I already know, rather than learning new things (even simple
tutorial steps), is nice.

~~~
hjwp3
thanks!

------
dcesiel
I recently started learning Django for a project I'm working on. I've been
reading the django book at djangobook.com, but it doesn't really talk about
writing tests. This is awesome, every Django developer should know how to do
this.

~~~
kroger
The Django Book is good, but it's incomplete and outdated. On the other hand,
the Django documentation talks about testing:

<https://docs.djangoproject.com/en/1.4/topics/testing/>

------
hjwp3
thanks for the post! (harry, the author)

