Skip to content

Testing

Ilya Sytchev edited this page Feb 27, 2018 · 15 revisions
  • Tests must not depend on other tests and must produce the same result every time
  • All tests must run reliably (no false positives)
  • Unit tests must run as fast as possible and must not use external resources like file system or network (mock and patch)
  • Use @override_settings to initialize settings explicitly in tests
  • Avoid relying on data migrations in Python tests
  • Separate Django unit tests from integration and functional tests
  • Without properly testing your code, you will never know if the code works as it should, now or in the future when the codebase changes. Countless hours can be lost fixing problems caused by changes to the codebase.
  • Testing helps you structure good code, find bugs, and write documentation.
  • Focus on unit tests. Write A LOT of these. These tests are much easier to write and debug vs. integration tests, and the more you have, the less integration tests you will need.

Testing in Django (Part 1) - Best Practices and Examples