Snapshot Testing: A New Era of Reliability
- Track:
- Testing, Quality Assurance, Security
- Type:
- Talk
- Level:
- intermediate
- Duration:
- 30 minutes
Abstract
In a nutshell: Snapshot testing simplifies testing large result sets, reducing manual work, especially for APIs and for data processing. I'll show you how to use it in your projects.
This talk is about:
- Snapshot testing: Usage and evolution.
- The inline-snapshot library, by Frank Hoffmann, the pytest plugin you were missing
- Main use cases
- Tests that are deterministic but have large outputs that are hard to write by hand.
- Refactor or approval testing: you need tests to ensure a function's result stays consistent during refactoring.
- Real-life examples with black+flake8 and ruff
- Examples with dirty-equals
- What is a meaningful diff or tricky bits of formatting and linting
- Handling different outputs depending on library versions
Relevant for you if:
- You test functions returning large outputs, like dicts or dataframes
- You deal with the main fields of usage: data processing, data pipelining, APIs
Main takeaways:
- General knowledge about snapshot testing
- Specific knowledge about the inline-snapshot library
- Real world use-cases of inline-snapshot: where to start, what to use it for, where it will boost your productivity
To cite Samuel Colvin, creator and founder of Pydantic, “inline-snapshots is transformative to how we write unit tests in Python! If you're using pytest, and you're not using inline-snapshots, you're wasting your time; simple as that.”
Requirements: A general idea about tests and different kinds of tests.