Ticket sales CLOSED!

Sunday 4:45 p.m.–5:05 p.m. in Terrace

Testing Django Projects at Scale

Ash Christopher

Audience level:
Novice

Description

Tests are extremely useful to developers, but as projects get larger, tests can begin to get in the way of a smooth delivery pipeline. In this talk I present some issues I have experienced, and offer 10 pragmatic guidelines that may help developers maximize their test usefulness.

Abstract

What makes good tests?

  • Tests should be as simple as possible.
  • Tests should run as quickly as possible.
  • Tests should avoid coupling with other tests.
  • Tests should communicate intent.

Canonical form of a test.

  • Setup pre-conditions
  • Perform operation under test.
  • Make assertions.
  • Benefits of following canonical form.

Testing tools

  • Factories (instead of fixtures).
  • Coverage.py
  • django-nose + multiprocess

Guidelines

  1. Tests should be as simple as possible.
  2. Each test method tests one thing, and one thing only.
  3. Only set up the minimum needed pre-conditions for your test.
  4. Create your pre-conditions explicitly - don't use shared helper methods outside your module.
  5. Name your TestCase methods to indicate what they actually test.
  6. Use factories, not fixtures.
  7. Use django.tests.TestCase instead of unittest2.TestCase
  8. Create mixins, not shared TestCases.
  9. Segment your tests.
  10. Don't use setupClass() or tearDownClass()

Get in touch