Django Day Copenhagen 2023
- Talk: A minimal Django Testing Styleguide
- Event: Djanjo Day Copenhagen 2023, October 6th 2023
- Organiser: Django Danmark
- Where: Union, Nørrebro, Copenhagen
- Github repo: @jvzammit/cph23
A lot of material is out there to ensure that “style” is maintained for “non test” code.
But what is “style”? And why do we need a “style” guide? And why would we need a style guide for our tests code?
Explain to me with examples please.
When reading and doing further work on the talk, I realised there is no definitive styleguide.
The most suitable styleguide depends on the project, the team and the organisation as a whole. And it’s not something cast in stone.
The talk does not define a styleguide itself. But rather goes through:
- What to test
- How we think about tests, and
- How we should write them as a result
- This includes aspects of writing tests the team should agree on
- Agree on what to test — this affects how to write tests
- Code is read far more than it is written, so write tests you want to read
From which code samples were taken: https://github.com/jvzammit/cph23
- Software Engineering: A Practitioner’s Approach. European Adaptation. Fifth Edition. Roger S. Pressman. 2000.
- Software Engineering at Google. Curated by Titus Winters, Tom Manshreck & Hyrum Wright. O’Reilly. 2020. Read online at abseil.io
- Two Scoops of Django 1.5. Daniel Greenfeld and Audrey Roy. Today Daniel and Audrey Roy Greenfeld. feldroy.com
- Speed Up Your Django Tests. Adam Johnson. adamj.eu
- A minimal Django testing style guide. Original post on which I decided to dig deeper for this talk.
- TestPyramid by Martin Fowler.
- The wrong abstraction by Sandi Metz.
- Just Say No to More End-to-End Tests. Mike Wacker - Google Testing Blog.
- Why and how I get 100% test coverage for my Django projects, and you should too. Sasha Romjin.
- Given-When-Then - Martin Fowler.
- Arrange-Assert-Act - Bill Wake.
Docs and Packages
- unittest module - Python’s standard library.
- Testing in Django - Django docs.
- Radon package’s Introduction to Code Metrics.
- time-machine and freezegun, and comparison by time-machine’s author.
- Conventions for test discovery - pytest.
Example style guides
- Python Testing Style Guide - Octopus Energy.
- My Python testing style guide - Thea “Stargirl” Flowers.
- The Testing Trophy by @kentcdodds
- Testing on the Toilet - Don’t Put Logic in Tests by @deliberatecoder
- Discussion about usage of cyclomatic complexity metric in Python projects - StackOverflow.com