> 1. where to define the testing? in models.py or in tests.py? I´d like  
> to seperate the testing from models.py, so how can I write doctests  
> in a seperate file (the example in the django documentation only  
> explains seperate unit-testing)?

my understanding is that doctests can only be (for the
better...one might be able to monkey-patch them from remote
modules, but it's ugly) in the module they're testing.  Unit
tests don't have this limitation and can be put in separate files.

> 2. can I make a test-directory (and does that make sense) for all my  
> tests or do I have to use the application-directories? within  
> django_src, there´s a directory called "tests" for example.

With unit tests, yes.  I had found that having everything in a
single tests.py started to get too big to comfortably manage.
I've done this with a tests/ folder with an __init__.py file that
imports * from all my test modules:

~/proj/app/tests/__init__.py
~/proj/app/tests/model1.py
~/proj/app/tests/model2.py
~/proj/app/tests/view1.py
...

and __init__.py contains

  from model1 import *
  from model2 import *
  from view1 import *
  ...

one has to be slightly careful of naming clashes in your testing
modules, however these just involve the class names (of your
testing classes) so it's pretty easy to prevent conflicts.

> 3. where do I find some examples (besides the django docs)?

I wish I could provide more info here...for the most part, it's
just standard Python testing, so any resources on general testing
in python should be helpful.  For such resources, I think the
F-bot and Ian Bickling have posted some good web pages that
supplement the more terse docs.python.org descriptions of
testing.  A little googling might be in order.

There are a couple django-specific items, such as fixtures (a
little sparsely documented, but this list has helped with some
clarifications, so the archives may be useful) and the custom
test object that supports them (along with some other nicities).
 However, once you're comfortable with regular Python testing, at
least the custom Django test object is easy to understand.
Fixtures are still a bit fuzzy for me.

> 4. does anyone know about a simple "how-to" on testing? something  
> like "step 1: setup the testing-database", "step 2: create a test- 
> directory (or use the app-dir or whatever)" ... ?

One of the beauties of Django is that, when you run "./manage.py
test", it takes care of creating the testing DB, populating it
with any initial data (fixtures) specified for each test,
clearing the DB between tests, etc.

I don't have any good pointers to a step-by-step, but I find that
writing my tests first and then writing the code to implement
them helps keep me focused on (1) having automated testing to
prevent regressions, and (2) the very next task at hand (rather
than implementing miles ahead of myself in a direction I didn't
need to go).

Just my early-morning thoughts on Django+testing

-tim










--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to