property-based_skill

This skill helps you apply John Hughes property-based testing concepts to Python code, generating inputs, checking invariants, and shrinking failures.
  • Python

3

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill copyleftdev/sk1llz --skill property-based

  • SKILL.md22.4 KB

Overview

This skill teaches property-based testing in the style of John Hughes (QuickCheck). It focuses on writing general properties instead of example tests, using randomized generators to explore inputs, and shrinking failures to minimal counterexamples for faster debugging. It is implemented with Python-friendly patterns and practical guidance for integration into CI.

How this skill works

You express invariants or laws (roundtrip, idempotence, algebraic, equivalence) as properties that must hold for all generated inputs. A generator produces thousands of random cases, runs the property against each, and when a failure appears the framework repeatedly applies shrink strategies to find a minimal failing example. Tests are repeatable via seeds and tuned by test count and generator size parameters.

When to use it

  • Testing pure functions with clear invariants (sort, normalize, encode/decode).
  • Validating algorithms and data structures against algebraic laws and invariants.
  • Comparing new implementations to known-correct or naive oracles.
  • Fuzzing parsers, serializers, and deserializers for roundtrip safety.
  • CI regression checks with reproducible seeds and many iterations.

Best practices

  • Prefer properties that state true invariants over enumerating examples.
  • Provide custom generators that model real input distributions and support shrinking.
  • Always implement shrinking: minimal counterexamples speed triage and fixes.
  • Run many iterations (1000+ when practical) and set seeds for CI reproducibility.
  • Split complex behavior into multiple orthogonal properties for clearer failures.

Example use cases

  • Assert serialize(deserialize(x)) == x for data structures and blob formats.
  • Verify sort preserves length and produces an ordered permutation of input.
  • Check idempotence: normalize(normalize(s)) == normalize(s) for input sanitizers.
  • Compare optimized algorithm output to a simple/reference implementation across random inputs.
  • Fuzz parser then shrink the smallest input that causes a crash or mis-parse.

FAQ

Start with 100–1000 during development; use 1000+ in CI for higher confidence. Increase counts for complex input spaces.

What if shrinking is slow or fails?

Improve generators to produce shrink-aware candidates and implement targeted shrink strategies (e.g., remove elements, halve numbers). Limit max shrinks to keep runtime bounded.

When should I not use property-based testing?

Avoid it for heavily side-effectful code that cannot be isolated or for behaviors lacking clear, testable invariants. Use example tests for tiny, fixed scenarios that need explicit documentation.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
property-based skill by copyleftdev/sk1llz | VeilStrat