RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Fredoline Eruo
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /How-to
  5. /How to set up property-based testing by prompting an AI to generate edge cases for your functions
HOW-TO · DEV

How to set up property-based testing by prompting an AI to generate edge cases for your functions

intermediate·20 min·By Fredoline Eruo
Target environment
Ubuntu 24.04 · Ollama 0.4.x
PREREQUISITES

Property-based testing library installed (Hypothesis for Python or QuickCheck for Haskell), at least one function with defined input/output contracts, and an AI assistant.

What this does

Property-based testing verifies that functions satisfy invariant properties across hundreds of automatically generated inputs. This guide explains how to engage an AI assistant to analyze function signatures, infer properties, and generate Hypothesis strategies and test cases that expose edge cases the developer may not have anticipated.

Steps

  1. Provide the AI assistant with the function source code, including docstrings, type hints, and any documented preconditions.
  2. Ask the AI to list five to ten property invariants the function should satisfy (for example: output is always positive, output length equals input length, result is deterministic for the same input).
  3. Request Hypothesis strategies for each input parameter that cover normal values, boundary values, empty inputs, and type mismatches.
  4. Ask the AI to produce the complete @given decorated test functions using these strategies and the identified invariants.
  5. Run the generated tests with pytest and observe any counterexamples that Hypothesis prints.
  6. Pass the counterexample back to the AI and request stronger invariants or additional preconditions.
  7. Add @settings configuration to control deadline, max_examples, and suppress_health_check parameters.
  8. Repeat steps 5–7 until no counterexamples remain or all failures are understood.

Verification

pytest tests/property/test_calculator.py -v

Expected output:

tests/property/test_calculator.py::test_division_by_zero_raises PASSED
tests/property/test_calculator.py::test_result_always_positive PASSED
  Hypotheses found 0 failing examples.

Common failures

  1. Hypothesis reports a counterexample that violates the property — The function contains a real bug. Fix the function code and re-run to confirm the counterexample no longer appears.
  2. Generated strategy produces type errors — The Hypothesis strategy generates values of the wrong type. Update the strategy definition to match the expected input type, or filter invalid values using .filter().
  3. Tests run but coverage is low — The AI generated strategies that only cover a narrow range of inputs. Ask the AI to broaden the strategy ranges and add boundary value cases explicitly.
  4. DeadlineExceeded health check warnings — Generated test functions are too slow. Reduce the example count or use @settings(deadline=None) to disable deadline enforcement.

Related guides

  • Create integration test suites for REST API endpoints (guide 25)
  • Test and iterate on system prompt designs (guide 32)
← All how-to guidesCourses →