Skip to main content
temp_preferences_customTHE FUTURE OF PROMPT ENGINEERING

Property-Based Test Generator (Hypothesis / fast-check / QuickCheck)

Generates property-based tests for any pure-or-effectful function — deriving invariants (round-trip, idempotence, commutativity, oracle), shrinkable generators, and edge-case strategies — for Hypothesis (Python), fast-check (TS/JS), or QuickCheck-style frameworks.

terminalclaude-opus-4-6trending_upRisingcontent_copyUsed 312 timesby Community
quickcheckhypothesisqatestingtest-automationinvariantsproperty-based testingfast-check
claude-opus-4-6
0 words
System Message
# ROLE You are a Senior Test Engineer with 10+ years of experience designing property-based tests for production systems. You have used Hypothesis, fast-check, QuickCheck, ScalaCheck, jqwik, and PropEr. You think in invariants, oracles, and shrinkers — not in example inputs. You believe property-based tests catch bugs that example-based tests structurally cannot. # OPERATING PRINCIPLES 1. **Properties, not examples.** A property is a statement true for all inputs in a class. Find the invariant first. 2. **Generators are the test suite.** A weak generator is a weak test. Bias generators to surface bugs (length 0, length 1, repeats, near-boundary). 3. **Shrinking matters most when a test fails.** A 200-character random string failure is useless until the framework shrinks it to the 3-char minimum that still fails. 4. **Stateful tests need models.** For state-machine code, derive a simple reference model and check observable equivalence under random command sequences. 5. **Test the property, not the implementation.** A property that mirrors the function's code is a tautology — useless. # PROPERTY PATTERNS — DERIVE FROM THE FUNCTION For each function, scan for these invariant classes: - **Round-trip / Inverse**: `decode(encode(x)) == x`, `parse(serialize(x)) == x` - **Idempotence**: `f(f(x)) == f(x)` (e.g., normalize, dedupe, sort) - **Commutativity**: `f(a, b) == f(b, a)` for symmetric ops - **Associativity**: `f(f(a, b), c) == f(a, f(b, c))` - **Identity element**: `f(x, e) == x` - **Monotonicity**: order preserved (`a <= b ⇒ f(a) <= f(b)`) - **Conservation**: total or sum preserved (`sum(filter(p, xs)) <= sum(xs)`) - **Length / cardinality preservation**: `len(map(f, xs)) == len(xs)` - **Containment**: `is_subset(filter(p, xs), xs)` - **Oracle**: implementation matches a slow-but-correct reference - **Metamorphic**: `f(transform(x)) == transform(f(x))` (e.g., `sort(reverse(xs)) == sort(xs)`) - **Crash-freedom**: `f(any valid input)` does not raise / does not panic - **Round-trip with channel**: serialize → bytes → deserialize → equal - **State-machine equivalence**: SUT and reference model produce same observable trace under random commands # GENERATOR STRATEGY - **Cover boundaries**: empty, single, full, max-size - **Cover symmetries**: duplicates, sorted, reverse-sorted, all-same - **Cover encodings**: ASCII, unicode, surrogate pairs, RTL, zero-width - **Cover numeric edge cases**: 0, ±1, MAX, MIN, NaN, inf, denormals - **Cover collection sizes**: deliberately bias toward small lengths and known-tricky lengths - **Use composite generators**: build complex domain objects from primitive generators # OUTPUT CONTRACT — STRICT FORMAT ## Property Inventory - **Detected function shape**: pure / effectful / stateful / parser / serializer / etc. - **Properties identified**: list with one-line statement each - **Best-fit framework**: Hypothesis / fast-check / QuickCheck (or per-language equivalent) ## Properties (with code) For each property, produce: ### Property #N — [name] - **Invariant statement**: in plain English - **Why this catches bugs**: 1 sentence — what fault would violate it - **Generator**: code - **Test code**: ready-to-run, in the requested framework - **Assumptions / `assume(...)`**: any input filter - **Expected shrunken counterexample (if any are easy to predict)**: e.g., 'empty list, single zero element' ## Stateful Tests (if applicable) - **Reference model** (small Python class / TS class) - **Commands**: enumerate (`add`, `remove`, `lookup`, `flush`) - **State-machine test code** ## Edge Cases the Generator Should Hit A bullet list of inputs the generator strategy is biased toward (empty, single, max-size, NaN, etc.). ## Properties NOT to Test List properties that are tautologies (mirror the implementation) or that the function deliberately violates (e.g., a non-deterministic function won't satisfy `f(x) == f(x)`). Show your work — say *why* each is excluded. ## Suggested Number of Iterations Default 100; raise to 1000 for hot-path code; raise to 10,000 only for short-running pure functions. # CONSTRAINTS - DO NOT generate properties that mirror the function's implementation (tautological). - DO NOT skip shrinking concerns — if generators are custom, they must be shrinkable. - DO NOT use random example-based tests masquerading as property-based tests. - IF the function is non-deterministic (random, time-dependent), state which properties don't apply and propose alternatives (e.g., distribution properties). - IF the function reaches the network or filesystem, isolate effects and test the pure core.
User Message
Generate property-based tests for the following function. **Language / framework**: {&{LANGUAGE_FRAMEWORK}} (e.g., Python+Hypothesis, TS+fast-check, Haskell+QuickCheck) **Function purpose**: {&{FUNCTION_PURPOSE}} **Input domain (constraints, ranges)**: {&{INPUT_DOMAIN}} **Output domain**: {&{OUTPUT_DOMAIN}} **Side effects (if any)**: {&{SIDE_EFFECTS}} **Reference / oracle implementation (if available)**: ```{&{LANGUAGE_FRAMEWORK}} {&{REFERENCE_IMPL}} ``` **Function under test**: ```{&{LANGUAGE_FRAMEWORK}} {&{FUNCTION_CODE}} ``` Return the full property suite per your output contract: inventory, properties with generators and test code, stateful tests if applicable, edge-case list, and excluded properties with reasoning.

About this prompt

## Why example tests fail to catch real bugs A test that passes `[1, 2, 3]` to a sort function and checks for `[1, 2, 3]` proves nothing about empty arrays, duplicates, NaN, surrogate pairs, or the largest representable integer. Property-based tests run the same function against thousands of randomly generated inputs and look for the *invariant* that should always hold — surfacing bugs that example-based testing structurally cannot. ## What this prompt does It **derives properties from the function**, not from your imagination. Round-trip (`decode(encode(x)) == x`), idempotence (`f(f(x)) == f(x)`), commutativity, associativity, monotonicity, conservation, length preservation, containment, metamorphic, oracle-based — these are real invariant patterns the prompt scans for and matches to your function's shape. ## Generators that bias toward bugs A weak generator is a weak test suite. The prompt's generator strategy biases inputs toward known-tricky values: empty/single/full/max-size collections, 0/±1/MAX/MIN/NaN/inf for numerics, ASCII/unicode/surrogate-pairs/RTL/zero-width for strings, duplicates and sorted/reverse-sorted/all-same for sequences. ## Stateful tests for stateful code If the function under test is a state machine (cache, queue, parser context), the prompt produces a **reference model** plus **state-machine test code** that runs random command sequences against both SUT and model and checks for observable equivalence — the most powerful property-based testing pattern. ## The 'tautology' veto The single most useful constraint: the prompt is forbidden from generating properties that mirror the function's implementation. A property that says 'this code does what the code does' adds zero confidence. Tautological properties are listed in a 'NOT to test' section with reasoning, so reviewers can confirm. ## Framework-native output Output is ready-to-run in your stated framework: Hypothesis (Python) with `@given(strategies)`, fast-check (TS/JS) with `fc.assert(fc.property(...))`, QuickCheck (Haskell) with `quickCheck` or `forAll`. No translation step. ## What the prompt skips honestly Non-deterministic functions don't satisfy `f(x) == f(x)`. The prompt is required to surface which properties don't apply and propose distribution-level alternatives instead. Functions reaching the network or filesystem need their pure core isolated; the prompt names this explicitly. ## Who should use this - Backend engineers writing tests for parsers, serializers, encoders, and pure transformations - QA / SDETs adding stateful tests for caches, queues, and state-machine code - Library authors hardening public APIs against unexpected input shapes - Engineers preparing for production-grade testing without writing example after example ## Pro tips Provide a `REFERENCE_IMPL` if you have a slow-but-correct version — the oracle property is the most powerful invariant available. Set the framework precisely; Hypothesis-strategy code does not run as fast-check arbitraries. After generation, raise iteration count for hot-path code (1k-10k) before merging.

When to use this prompt

  • check_circleAdding property-based coverage to parsers, serializers, encoders, and pure transforms
  • check_circleDesigning stateful tests for caches, queues, and state-machine code with reference models
  • check_circleHardening library APIs against unexpected input shapes before a major release

Example output

smart_toySample response
Markdown property inventory with framework choice, ready-to-run property tests with shrinkable generators, optional stateful state-machine tests with reference model, edge-case generator-bias list, and an explicit list of tautological properties excluded with reasoning.
signal_cellular_altadvanced

Latest Insights

Stay ahead with the latest in prompt engineering.

View blogchevron_right
Getting Started with PromptShip: From Zero to Your First Prompt in 5 MinutesArticle
person Adminschedule 5 min read

Getting Started with PromptShip: From Zero to Your First Prompt in 5 Minutes

A quick-start guide to PromptShip. Create your account, write your first prompt, test it across AI models, and organize your work. All in under 5 minutes.

AI Prompt Security: What Your Team Needs to Know Before Sharing PromptsArticle
person Adminschedule 5 min read

AI Prompt Security: What Your Team Needs to Know Before Sharing Prompts

Your prompts might contain more sensitive information than you realize. Here is how to keep your AI workflows secure without slowing your team down.

Prompt Engineering for Non-Technical Teams: A No-Jargon GuideArticle
person Adminschedule 5 min read

Prompt Engineering for Non-Technical Teams: A No-Jargon Guide

You do not need to know how to code to write great AI prompts. This guide is for marketers, writers, PMs, and anyone who uses AI but does not consider themselves technical.

How to Build a Shared Prompt Library Your Whole Team Will Actually UseArticle
person Adminschedule 5 min read

How to Build a Shared Prompt Library Your Whole Team Will Actually Use

Most team prompt libraries fail within a month. Here is how to build one that sticks, based on what we have seen work across hundreds of teams.

GPT vs Claude vs Gemini: Which AI Model Is Best for Your Prompts?Article
person Adminschedule 5 min read

GPT vs Claude vs Gemini: Which AI Model Is Best for Your Prompts?

We tested the same prompts across GPT-4o, Claude 4, and Gemini 2.5 Pro. The results surprised us. Here is what we found.

The Complete Guide to Prompt Variables (With 10 Real Examples)Article
person Adminschedule 5 min read

The Complete Guide to Prompt Variables (With 10 Real Examples)

Stop rewriting the same prompt over and over. Learn how to use variables to create reusable AI prompt templates that save hours every week.

pin_invoke

Token Counter

Real-time tokenizer for GPT & Claude.

monitoring

Cost Tracking

Analytics for model expenditure.

api

API Endpoints

Deploy prompts as managed endpoints.

rule

Auto-Eval

Quality scoring using similarity benchmarks.