Wiki: Write Thousands of Tests and Catch Bugs Earlier with Property-Based Testing

For agents: Markdown version · Wiki index · Explore

Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.

Summary

The speaker discusses property-based testing as an effective strategy to write numerous tests and catch bugs earlier with less effort. The talk explains how generating diverse inputs and verifying properties or state transitions allows computers to find edge cases and provide minimal failing examples. Through practical examples including a sorting function and a web application with state, the audience learns how property-based testing compares to traditional testing and how to apply it effectively.

Key points

  • 1:15 Traditional testing is often expensive to write and maintain, which is why property-based testing is introduced as a more efficient alternative.
  • 2:16 Instead of specifying exact inputs and outputs, the developer defines input generators and output properties, letting the computer find failing cases.
  • 5:30 Property-based test frameworks automatically perform shrinking to find the smallest and simplest input that still causes the test to fail.
  • 7:35 Stateful testing extends the technique to APIs with underlying state by defining API operations, a state model, state transitions, and post-conditions.
  • 21:04 Challenges of property-based testing include handling performance issues and finding sufficiently strong properties that actually catch bugs.
  • 23:05 Common property-based testing patterns such as invariants, round-trip checks, and test oracles help developers write more effective tests.

Takeaways

  • Use property-based testing to generate diverse inputs automatically and uncover unexpected edge cases.
  • Apply stateful testing patterns to verify complex sequences of API calls against a simplified state model.
  • Leverage test shrinking to quickly isolate and debug minimal failing scenarios.

Questions this talk answers

  • What is the difference between traditional example-based testing and property-based testing?
  • How do you design strong properties for a property-based test without duplicating the implementation logic?
  • When should a developer choose stateful testing over standard unit tests?

Technologies

Python, HTTP, JSON

Tags

automation, bug hunting, property-based testing, software architecture, testing