Friday, May 1, 2015

Re: The best way to mock querysets

On Fri, May 1, 2015 at 5:17 AM, Avraham Serour <tovmeod@gmail.com> wrote:
> In my opinion you shouldn't, you should set the test data and make a real
> query then compare results, you shouldn't care how the function got the
> data, but that it got it correctly.


that's part of a much bigger religious war, with "unit tests" at one
extreme and "integration tests" at the other.

even without aiming for unittest purity, the "test only the code
you're testing" idea would clearly advise for mocking the database.
of course, that means many more tests for the database layer itself,
which in turn make the OP's wish for quick tests all much more
important.

but when doing TDD, the favored tests aren't necessarily of the
unittest variety; they lean somewhat more towards functional tests,
almost integration tests. IOW: if it's a requirement for the code to
work decoupled from the database, then test it in isolation. if not,
then the minimal test (and minimal code to pass it) is to assume the
database layer is already well tested by the framework (and it is!),
and you're free to assume it in the tests.

cheers,

--
Javier

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFkDaoR2nsDrqmEWmTGnKqbaEoci%2BoJ-%3Dy%2Byg2vdP6vue3ssdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment