On Jul 16, 1:20 am, Joshua Russo <josh.r.ru...@gmail.com> wrote:
> I'm in the process of implementing testing (both doc tests and unit
> tests) though I'm having some conceptual difficulty. I'm not sure how
> far to take the testing. I'm curious what people concider an
> appropriate level of testing.
>
> This thought struck me most when I was going through the testing
> documentation, in the section regarding the testing of models. It
> seems to me that very little logic generally goes into the model
> classes. At least for me, I have far more logic in admin.py and
> views.py.
>
> What are peoples thoughts on testing models? What exactly are you
> testing for there? How do you gauge code that should be tested versus
> code that doesn't really need it?
>
> Thanks for your help
> Josh

The key thing is to know when to rely on Django's own tests, and when
to write your own. There's absolutely no point, for example, to write
tests that check that you can instantiate and save a model, and that
the values in the database match the values you pass in. That's
covered entirely by Django, and is very well-tested.

So what your unit tests need to cover is the bits where your code
interacts with and builds on the things that Django provides - ie the
business logic. This can be in custom model methods, or in views, or
library modules.

Personally, I always have trouble separating functional testing from
unit testing, so my so-called unit tests seem to always end up using
the test client to get a page and checking to see if it contains the
right data. That's certainly a *part* of unit testing, but you also
need to break things down to smaller units so you can test individual
bits of logic, and this is very difficult to do right.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to