Skip to content

Playing with django.test

This morning I poked around the Django testing framework and altough is definitely usable as a simple testing framework (unittest and doctest) it lacks a massive fixture framework (like Rails for instance).

I also have some random problems using test.Client() for POST resulting in some HTTP 500 response instead of 200.

In the meantime I tried using twill to fulfill the holes in the testing infrastructure but it seems to be useless for our web app because the forms use an image to submit and twill understands only submit buttons.

The solution seems to be Selenium. It’s handy and powerful. I can test visually without have to remember line by line in which state am I and go back and forth from Firebug to TextMate to see what name has the view I have to check after. I’m not done testing with Selenium but I like it. It also produces Python source code I can integrate with the app.

12 Comments

  1. michele wrote:

    At work, for a strongly interactive and AJAXy application, we are having good results with Sahi. Selenium had problems with asynchronous requests.

    Monday, January 29, 2007 at 3:04 pm | Permalink
  2. Christoph Neuroth wrote:

    Hi,

    I also played around with it some days ago and for POST Requests, I allways got 301 (or 302? something like that) responses instead of 200… Do you have any clues why that is?

    “Fixtures” are being worked on as the documentation states. Don’t even know what that is though ;)

    Monday, January 29, 2007 at 7:09 pm | Permalink
  3. Lawrence wrote:

    301/302 are redirects. I think you should see in the body but usually it’s not a wrong response code.

    A fixture is simply a collection of data to feed the testing framework.

    Monday, January 29, 2007 at 7:18 pm | Permalink
  4. There is a usable patch for fixtures attached to http://code.djangoproject.com/ticket/2333

    on a separate but related note, I’m working on a standalone module, fixture (http://code.google.com/p/fixture/), which is a framework of sorts, pluggable into any test suite. I’m holding off on supporting django though, since there is so much work being done on their own fixtures api.

    Monday, January 29, 2007 at 9:20 pm | Permalink
  5. Lawrence wrote:

    Yes I know about that patch. I’m gonna wait until it will be merged in the trunk by the way

    Tuesday, January 30, 2007 at 12:24 am | Permalink
  6. Indeed, I’m waiting for #2333 myself :) Stay tunned, because I think we’re almost there — there are just a few small things to iron out first.

    Tuesday, January 30, 2007 at 7:05 pm | Permalink
  7. Lawrence wrote:

    Cool Jacob! I’ll keep on lurking django-dev ;-)

    Tuesday, January 30, 2007 at 7:28 pm | Permalink
  8. Maxime Biais wrote:

    Hi !

    I’m using JMeter: http://jakarta.apache.org/jmeter/ to test and benchmark my django apps.

    Wednesday, February 21, 2007 at 7:27 pm | Permalink
  9. fonso wrote:

    Christopher, Maybe your URLs didn’t have an ending slash? If they didn’t, Django is configured by default to append it and redirect to the resulting URL.

    Wednesday, March 7, 2007 at 5:40 pm | Permalink
  10. Lawrence wrote:

    @fonso: the problem has been fixed weeks ago and I honestly tell you that I don’t remember what was it. I have to check in svn logs :-)

    Thanks anyway

    Wednesday, March 7, 2007 at 5:47 pm | Permalink
  11. Interesting that you like fixtures because most of the people I know, myself included, are always looking for alternatives. Fixtures seem like a nice idea until you get an application of any serious size or complexity. They really fall down. The consensus seems to be to put more reliance on mocking.

    Saturday, May 5, 2007 at 3:03 am | Permalink
  12. Lawrence wrote:

    To be honest I also used stubs in my project. The deal is using fixtures to test against data resembling the real data. That’s why they are useful in Django. Not as lean as Rails’ but not bad :-)

    Saturday, May 5, 2007 at 10:57 am | Permalink

Additional comments powered by BackType