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