mcpField
P
property-based-testing

property-based-testing

github.com/aj-geddesTesting & quality374451 installsUpdated 34w ago
Repository

About property-based-testing

property-based-testing is a testing skill that checks general properties and invariants using automatically generated inputs. It helps find edge cases and complements example-based tests.

Key features

  1. 01Automatic input generation
  2. 02Checks for general properties and invariants
  3. 03Edge case discovery
  4. 04Round-trip encoding and decoding checks
  5. 05Shrinking of failing cases

Use cases

  1. 01Verifying mathematical properties of algorithms
  2. 02Testing parsers and serializers
  3. 03Checking data transformations and data structure operations

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill property-based-testing

After installing, type/property-based-testingin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
fast-check-for-javascripttypescript.md
hypothesis-for-python.md
junit-quickcheck-for-java.md
scripts/
scaffold-tests.sh
templates/
test-template.js

Details

From the project README

Property-Based Testing

Table of Contents

Overview

Property-based testing verifies that code satisfies general properties or invariants for a wide range of automatically generated inputs, rather than testing specific examples. This approach finds edge cases and bugs that example-based tests often miss.

When to Use

  • Testing algorithms with mathematical properties
  • Verifying invariants that should always hold
  • Finding edge cases automatically
  • Testing parsers and serializers (round-trip properties)
  • Validating data transformations
  • Testing sorting, searching, and data structure operations
  • Discovering unexpected input combinations

Quick Start

Minimal working example:

# test_string_operations.py
import pytest
from hypothesis import given, strategies as st, assume, example

def reverse_string(s: str) -> str:
    """Reverse a string."""
    return s[::-1]

class TestStringOperations:
    @given(st.text())
    def test_reverse_twice_returns_original(self, s):
        """Property: Reversing twice returns the original string."""
        assert reverse_string(reverse_string(s)) == s

    @given(st.text())
    def test_reverse_length_unchanged(self, s):
        """Property: Reverse doesn't change length."""
        assert len(reverse_string(s)) == len(s)

    @given(st.text(min_size=1))
    def test_reverse_first_becomes_last(self, s):
        """Property: First char becomes last after reverse."""
        reversed_s = reverse_string(s)
        assert s[0] == reversed_s[-1]
        assert s[-1] == reversed_s[0]
// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Hypothesis for PythonHypothesis for Python
fast-check for JavaScript/TypeScriptfast-check for JavaScript/TypeScript
junit-quickcheck for Javajunit-quickcheck for Java

Best Practices

✅ DO
  • Focus on general properties, not specific cases
  • Test mathematical properties (commutativity, associativity)
  • Verify round-trip encoding/decoding
  • Use shrinking to find minimal failing cases
  • Combine with example-based tests for known edge cases
  • Test invariants that should always hold
  • Generate realistic input distributions
❌ DON'T
  • Test properties that are tautologies
  • Over-constrain input generation
  • Ignore shrunk test failures
  • Replace all example tests with properties
  • Test implementation details
  • Generate invalid inputs without constraints
  • Forget to handle edge cases in generators

Comments

Markdown supported