Hi Joshua, whenever I override some of the Form methods, I make sure I have tests that cover the code I wrote. In particular, when I override the save() method on a ModelForm, I make sure that - the Model save() gets called from the Form save() if the form is valid - my Form save() returns the object (a classic oversight for me).
I also try to make sure required fields are indeed required, and that validation does validate/fail as expected. I also like having good unit tests for my forms because then my view unit tests can stop at the form level. What I mean is that if a view uses a form, I can just test that the correct type of form is instantiated and passed into the template context, and that if I feed valid data to the view, the form save() is called. This checks that the view makes correct use of the form, and I trust the form to behave, because it has its own tests. Rodrigue On Jul 17, 3:57 am, Russell Keith-Magee <freakboy3...@gmail.com> wrote: > On Fri, Jul 17, 2009 at 9:56 AM, Joshua Partogi<joshua.part...@gmail.com> > wrote: > > Hi Russ, > > > To expand this question. Do we use unittest for testing forms? Because from > > what I see in the code, doctest only tests your model. CMIIW. > > I shall. I don't know where you got that idea. :-) > > doctests are just a way of expressing tests. It has no inherent > strengths, weaknesses or ties to model testing. It's just a way of > testing based on a mock shell - i.e., "If I run X at the python > prompt, I expect to see Y". You can do this with models, with forms, > or anything else that can be invoked as a Python command. > > You can also use unittest to do exactly the same thing. The assertion > facilities for unit tests are a little easier to use (since it isn't > just based on string checking), but fundamentally, a unittest is just > a way to bundle a series of commands whose output can then be asserted > for validity. > > Django's TestCase provides a few extra helpful bits for web app > testing - such as a built in test client, fixture loading, etc - but > that's only because it's easier to subclass unittest.TestCase than it > is to subclass the doctest framework. > > In short, use whatever you find convenient. Both doctest and unittest > are valid and useful testing frameworks. In my experience, doctests > are usually easier to write initially, but unittests prove more useful > in the long term - but that's entirely subjective. YMMV. > > Yours > Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---