Property-Based Testing

When to use: parsers, serializers, data transformers, encoders/decoders, validators — anything where "for all valid inputs X, property Y holds."

The principle: Instead of testing specific examples, describe properties of the output and let the framework generate hundreds of random inputs to try to falsify them.

Platform tools:

Platform Library Install
Python Hypothesis pip install hypothesis
TypeScript/JS fast-check npm install fast-check
Swift @Test(arguments:) (parameterized) Built into swift-testing
.NET FsCheck dotnet add package FsCheck
Kotlin/JVM jqwik Gradle/Maven dependency

At least one property test MUST be written per data transformation function. Examples:

  • encode(decode(x)) == x (round-trip)
  • sort(xs).length == xs.length (preservation)
  • parse(serialize(obj)).fields == obj.fields (fidelity)
from hypothesis import given
import hypothesis.strategies as st

@given(st.text())
def test_encode_decode_roundtrip(s):
    assert decode(encode(s)) == s
version
1.0.0
platforms
csharp, kotlin, python, swift, typescript
tags
property-based-testing, testing
author
Mike Fullerton
modified
2026-03-27

Change History

Version Date Author Summary
1.0.0 2026-03-27 Mike Fullerton Initial creation