property-based-testing

Solid

Property-based testing (PBT) patterns with fast-check (JS/TS), Hypothesis (Python), and gopter (Go). Generate random inputs, define invariants, shrink failures to minimal cases. Adapted from Trail of Bits. Use when testing pure functions, parsers, serializers, state machines, or any code where example-based tests miss edge cases.

Testing & QA 496 stars 41 forks Updated 1 months ago MIT

Install

View on GitHub

Quality Score: 86/100

Stars 20%
90
Recency 20%
75
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Property-Based Testing Instead of testing specific examples, define properties that must hold for ALL inputs. The framework generates hundreds of random inputs and finds the smallest failing case. ## When to Use PBT | Use Case | Property | |----------|----------| | Serialization roundtrip | `deserialize(serialize(x)) === x` | | Sort function | Output is ordered AND contains same elements | | Parser | Never crashes on any input | | Encoder/decoder | `decode(encode(x)) === x` | | State machine | Invariants hold after any sequence of operations | | Math/financial | Associativity, commutativity, identity, bounds | | API handler | Never returns 500 on valid input | | Data transformation | Output schema matches specification | ## When NOT to Use PBT - UI rendering tests (use visual regression) - Integration tests with external services (use contract tests) - Tests that need specific business scenarios (use example tests) - Tests where the oracle is as complex as the implementation ## fast-check (JavaScript/TypeScript) ### Setup ```bash npm install --save-dev fast-check ``` ### Basic Property ```typescript import fc from 'fast-check' // Property: sorting is idempotent test('sort is idempotent', () => { fc.assert( fc.property(fc.array(fc.integer()), (arr) => { const sorted = [...arr].sort((a, b) => a - b) const sortedTwice = [...sorted].sort((a, b) => a - b) expect(sorted).toEqual(sortedTwice) }) ) }) // Property: serialization roundtrip tes...

Details

Author
vibeeval
Repository
vibeeval/vibecosystem
Created
2 months ago
Last Updated
1 months ago
Language
C#
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category