AgentSkillsCN

property-based-tester

生成基于属性的测试用例,在数千个随机生成的输入中验证各项不变式。

SKILL.md
--- frontmatter
name: property-based-tester
description: "Generates property-based tests that verify invariants across thousands of randomly generated inputs."
version: "1.0.0"
tags: [testing, verification, random-generation, property-testing]
difficulty: intermediate
languages: [haskell, ocaml, rust, python, scala]
dependencies: [type-inference-engine, smt-solver-interface]

Property-Based Tester

Implements property-based testing frameworks that generate random test inputs and verify properties hold, finding edge cases that manual testing misses.

When to Use This Skill

  • Testing algebraic laws (monoid, functor, monad)
  • Verifying compiler transformations preserve semantics
  • Finding bugs in data structures
  • Fuzzing APIs with type-aware generation

What This Skill Does

  1. Generators: Builds random generators for types via combinators
  2. Property Definition: Defines properties as functions returning Boolean
  3. Shrinking: Implements minimal counterexample finding
  4. Statistics: Reports distribution of test inputs

Key Concepts

ConceptDescription
GeneratorProduces random values of a type
ShrinkerReduces failing inputs to minimal examples
PropertyInvariant that should hold for all inputs
CoverageDistribution of generated inputs

Tips

  • Write properties that should always hold, not just examples
  • Use shrinking to get minimal failing cases
  • Cover edge cases: empty, single element, large inputs
  • Combine with type-based generation for better coverage

Related Skills

  • smt-solver-interface - Symbolic verification
  • fuzzer-generator - Random testing
  • type-inference-engine - Type-aware generation

Canonical References

ReferenceWhy It Matters
QuickCheck: Lightweight Automatic TestingOriginal Haskell testing library
Hypothesis: Property-based testing in PythonPython ecosystem standard
Testing the Hard StuffRandom testing for critical software

Tradeoffs and Limitations

ApproachProsCons
Random generationFinds edge casesMay miss specific bugs
EnumerationComplete coverageState space explosion
Symbolic executionTargeted testingSlower, complex

Assessment Criteria

CriterionWhat to Look For
Generator coverageAll interesting cases covered
Shrinking effectivenessMinimal failing examples
Property correctnessProperties capture true invariants

Quality Indicators

Good: Good coverage, effective shrinking, correct properties ⚠️ Warning: Limited coverage, slow shrinking ❌ Bad: Wrong properties, no shrinking

Research Tools & Artifacts

Property-based testing frameworks:

ToolLanguageWhat to Learn
QuickCheckHaskellOriginal PBT
HypothesisPythonPython standard
Fast-CheckTypeScriptComposable
ScalaCheckScalaIntegration
Erlang QuickCheckErlangIndustrial

Research Frontiers

1. Stateful Testing

  • Goal: Test stateful systems
  • Papers: "QuickCheck Testing for Stateful Software"
  • Tools: StateMachines, sequences

Implementation Pitfalls

PitfallReal ConsequenceSolution
Weak propertiesFalse positivesStrengthen invariants