본문으로 건너뛰기
Skillpedia
테스트8.0k · #12694

property-based-testing

하는 일

테스트가 모든 입력에 대해 규칙을 정하고 도구가 반례를 찾는 속성 기반 테스트를 안내합니다. 손으로 고른 예시 목록보다 훨씬 넓게 검사하는 테스트를 원하는 개발자를 위한 것입니다.

사용하는 경우

  • ✓개발자가 몇 가지 예시가 아니라 입력 범위 전체를 다루는 테스트를 원할 때.
  • ✓개발자가 인코더와 디코더 쌍, 파서, 정렬 함수를 테스트할 때.
  • ✓개발자가 퍼징 도구로 Solidity 계약의 불변식을 확인하고 싶은 경우.

스킬 링크

https://github.com/trailofbits/skills/blob/main/plugins/property-based-testing/skills/property-based-testing/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/trailofbits/skills/blob/main/plugins/property-based-testing/skills/property-based-testing/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“제 JSON 인코더와 디코더에 대해, 모든 왕복을 확인하는 속성 기반 테스트를 써 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 스킬은 코드에서 왕복, 멱등성, 불변식 같은 속성을 찾아 그것을 명시하는 테스트를 씁니다. 코드에 테스트하기 좋은 명확한 구조가 있는지 확인하고, 없으면 리팩터링을 제안합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Property-Based Testing

An example test asserts one point. A property asserts a rule over the whole input domain and lets the generator hunt for the counterexample. That trade is worth making when the code has an algebraic shape — an inverse, an invariant, an oracle — and not otherwise. Code with no such shape gets example tests; saying so is a valid outcome.

Check first whether the shape is missing or merely buried. A calculation wrapped in I/O, a string built by concatenation, an in-place mutation — each has a property and no seam to assert it through. See references/refactoring.md before concluding there is nothing to assert.

Property catalog

Property Formula Where it applies
Roundtrip decode(encode(x)) == x Serialization, conversion pairs
Inverse f(g(x)) == x encrypt/decrypt, compress/decompress
Oracle new(x) == reference(x) Optimization, refactoring, reimplementation
Idempotence f(f(x)) == f(x) Normalization, formatting, sorting
Invariant Holds before and after Any transformation, contract state
Easy to verify is_sorted(sort(x)) Complex algorithms with cheap checkers
Commutativity f(a, b) == f(b, a) Binary and set operations
Associativity f(f(a,b), c) == f(a, f(b,c)) Combining operations
Identity f(x, e) == x Operations with a neutral element

Strength ordering, weakest to strongest: no crash → type preservation → invariant → idempotence → roundtrip / oracle.

Assert the strongest property the code supports. "No crash" alone rarely justifies the dependency — if that is all you can find, either a small rearrangement exposes something stronger, or the honest report is that this code is a poor PBT candidate. Rule out the first before settling for the second.

The two ways a property test asserts nothing

  • Tautology. assert add(a, b) == a + b restates the implementation; no bug they share can fail it. Pick a property that constrains the function without recomputing it. Note the exception: f(x) == f(x) is a genuine determinism property when f is not obviously pure — serializers over dicts or sets, hashing, anything reading the clock.
  • Vacuity. assume() that filters out nearly every input passes without exercising anything, and self-contradictory assume() passes having run zero cases. Push constraints into the strategy so the generator produces valid inputs directly.

Where to look next

Load the one that matches the task in front of you:

Task File
Writing new tests, designing strategies references/generating.md
The code has no property to assert yet references/refactoring.md
Reviewing existing property tests references/reviewing.md
A property test just failed references/interpreting-failures.md
Library choice, Echidna and Medusa references/libraries.md

Introducing PBT to a project that lacks it

If the project already uses a PBT library, just write the tests in it. If it does not, adding one is a dependency decision that belongs to the user — offer it once with the specific property you would write, and take the answer either way.

자주 묻는 질문

예시 기반 테스트보다 나은가요?

항상 그렇지는 않습니다. 확인할 명확한 규칙이 없는 코드에는 예시 기반 테스트를 유지해야 한다고 설명합니다.

어떤 도구를 다루나요?

Hypothesis, fast-check, proptest, jqwik, rapid, Echidna, Medusa를 나열합니다.

속성은 무엇인가요?

유효한 모든 입력에 대해 성립해야 하는 규칙입니다. 예를 들어 인코딩된 값을 디코딩하면 원래 값이 나와야 합니다.

상세 정보

작성자의 원본 설명

Writes, reviews, and debugs property-based tests — Hypothesis, fast-check, proptest, jqwik, rapid, and Echidna or Medusa for Solidity invariants. Use whenever tests should cover a whole input domain instead of a hand-picked list of examples: encode/decode and serialize/deserialize pairs, parsers, canonicalizers and normalizers, validators, numeric and Decimal types, comparators and sort order, data structures, and smart-contract state invariants. Also use when adding cases to an existing @given, fast-check, or proptest suite, when judging whether existing property tests assert anything real, a

repo: trailofbits/skills

인기도

GitHub 스타
8.0k
순위
#12694
라이선스
CC-BY-SA-4.0
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬