property-based-testing

Generates Hypothesis property-based tests, invariants, and stateful test strategies for Python code.

Updated Sep 2, 2026
One-click install
npx skills add https://github.com/Dazlarus/karl-code --skill property-based-testing-dazlarus
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: property-based-testing
Source: https://github.com/Dazlarus/karl-code/tree/main/.agents/skills/property-based-testing
Command: npx skills add https://github.com/Dazlarus/karl-code --skill property-based-testing-dazlarus

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires hypothesis, pytest.

What problem does it solve? Example-based unit tests only cover the cases a developer thinks to write, leaving edge cases and invariant violations undiscovered. This Skill guides the creation of property-based tests with Hypothesis that automatically generate inputs, shrink failures, and verify invariants across thousands of cases. ## Core Features & Use Cases - Property and Invariant Testing: Define properties like commutativity, reversibility, and non-negativity instead of hardcoded examples, and let Hypothesis search for counterexamples. - Custom Strategies and Stateful Testing: Build strategies for emails, dates, and URLs, and model stateful systems like shopping carts with RuleBasedStateMachine to verify invariants across operation sequences. - Use Case: When refactoring a data transformation function, write a property test asserting round-trip consistency (e.g., decode(encode(x)) == x) so Hypothesis finds edge cases like empty strings, unicode, and boundary values automatically. ## Quick Start Write a Hypothesis property-based test for my parse_date function that verifies it never crashes on arbitrary string input and raises ValueError for invalid formats.

Frequently Asked Questions about property-based-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a property-based test with Hypothesis in Python?▼

Use the @given decorator with strategies like st.integers() or st.text() to generate inputs, then assert a property that must always hold, such as commutativity or round-trip equality. Hypothesis runs many generated examples and shrinks any failure to a minimal counterexample.

What is the difference between property-based testing and unit testing?▼

Unit tests check specific hand-written examples, while property-based tests define general properties and generate hundreds of random inputs to verify them. Property-based testing excels at finding edge cases but is not suited for simple happy-path or business-rule scenarios.

How do I test stateful systems with Hypothesis?▼

Subclass RuleBasedStateMachine and define @rule methods for operations plus @invariant methods for conditions that must always hold. Hypothesis then generates random sequences of operations and checks the invariants after each step.

How do I create custom Hypothesis strategies for complex data?▼

Compose built-in strategies using st.builds, st.sampled_from, and .filter() to constrain generated values, such as emails containing '@' or dates within a range. Filters should not be too restrictive, or Hypothesis will struggle to generate valid examples.

When should I not use property-based testing?▼

Avoid property-based tests for simple happy-path checks, specific business rules, and integration tests against external dependencies. Use example-based unit tests for concrete scenarios and reserve property tests for complex logic and invariants.