agentleFS
mejbaurbaharmejbaurbahar/software-tester-skills/skills/property-based-testing/SKILL.md

property-based-testing

Skill1 starsChanged 53 days agoMITView on GitHub

Use when example-based tests miss edge cases — property-based testing with Hypothesis, fast-check, jqwik, QuickCheck, or proptest; invariants, round-trip, oracle and metamorphic properties, shrinking, stateful/model-based tests.

18 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use observability, simplify and 3 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • OpenAISkill

    observability

    Vercel Observability expert guidance — Drains (logs, traces, speed insights, web analytics), Web Analytics, Speed Insights, runtime logs, custom events, OpenTelemetry integration, and monitoring dashboards. Use when instrumenting, debugging, or optimizing application performance and user experience on Vercel.

    Also in 3 projects that use this

  • Hugging FaceSkill

    simplify

    Refactor code after tests pass. The "Refactor" phase of Red-Green-Refactor.

    Also in 3 projects that use this

  • Microsoft AzureSkill

    git-workflow

    Squad branching model: dev-first workflow with insiders preview channel

    Also in 3 projects that use this

  • SentrySkill

    security-review

    Finds exploitable application security vulnerabilities in code changes. Use for Warden security scans, appsec review, OWASP-style checks, authentication or authorization bugs, injection, XSS, SSRF, path traversal, secrets, unsafe crypto, webhook verification, open redirects, or sensitive data exposure.

    Also in 3 projects that use this

  • NVIDIASkill

    research

    Before designing a feature, research how comparable libraries solve the problem, check best practices, known pitfalls, and upstream changes. Use when starting a new feature, investigating an unfamiliar area, or the user asks to research something.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 17 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Instead of asserting f(3) == 9, assert a property that must hold for all inputs.

    line 13
  2. Very specific:

    Keep generators fast; set max_examples (default 100) up in CI nightly (1000+), down for PR (50).

    line 50

“Common” is measured: kept by at least 6 in 10 of the 17 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Property-Based Testing (PBT)

Instead of asserting f(3) == 9, assert a property that must hold for all inputs; the framework generates hundreds of cases, then shrinks any failure to a minimal counter-example.

Find properties (the hard part) — 7 patterns

  1. Round-trip: decode(encode(x)) == x (serializers, parsers, compress, crypto).
  2. Invariant: len(sort(xs)) == len(xs), output is ordered, total money conserved.
  3. Idempotence: f(f(x)) == f(x) (normalize, dedupe, PUT).
  4. Oracle: compare with a slow/simple reference implementation.
  5. Metamorphic: search(q + filter) ⊆ search(q); price(2×qty) == 2×price(qty).
  6. Commutativity/associativity where the domain promises it.
  7. No-crash / postcondition: for any valid input, no exception and result satisfies the contract.

Examples

# Python — Hypothesis
from hypothesis import given, strategies as st, settings
@given(st.lists(st.integers()))
def test_sort_props(xs):
    out = sorted(xs)
    assert len(out) == len(xs)
    assert all(a <= b for a, b in zip(out, out[1:]))
    assert sorted(out) == out            # idempotent
// TypeScript — fast-check
import fc from "fast-check";
test("json round-trip", () => {
  fc.assert(fc.property(fc.jsonValue(), v => expect(JSON.parse(JSON.stringify(v))).toEqual(v)));
});
pytest --hypothesis-seed=12345          # reproduce a failing run
npx jest --testTimeout=30000            # PBT can be slower

Generator design

  • Constrain to the valid domain with strategies (st.integers(0, 120)), not assume() filters that discard most inputs.
  • Build domain objects with composite strategies (@st.composite, fc.record). Include nasty values: empty, huge, unicode, NaN, negative zero, duplicates.
  • Keep generators fast; set max_examples (default 100) up in CI nightly (1000+), down for PR (50).

Stateful / model-based testing

Model the system as a simple state machine; generate random command sequences; compare real system to the model after each step (Hypothesis RuleBasedStateMachine, fast-check commands). Excellent for caches, queues, carts, DB wrappers, REST CRUD.

Reproducibility

Persist failing examples (Hypothesis .hypothesis/ DB; commit @example(...) for regression); log seeds in CI. Never mark a PBT flaky — a failure is a real counter-example (or a bad property).

Pitfalls

Re-implementing the function inside the property (tautology) · properties too weak (assert True) · non-determinism in the code under test · unbounded generators blowing runtime.

Related

unit-testing, fuzz-testing, test-design-techniques, mutation-testing

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.