मुख्य सामग्री पर जाएँ
Skillpedia
टेस्टिंग8.0k · #12694

property-based-testing

यह क्या करती है

Property-based टेस्टिंग का मार्गदर्शन करती है, जिसमें टेस्ट सभी इनपुट के लिए एक नियम बताता है और टूल प्रतिउदाहरण खोजता है। यह उन डेवलपर्स के लिए है जिन्हें हाथ से चुने उदाहरणों से कहीं ज़्यादा कवर करने वाले टेस्ट चाहिए।

कब इस्तेमाल करें

  • ✓जब डेवलपर को कुछ उदाहरणों के बजाय इनपुट की पूरी रेंज कवर करने वाले टेस्ट चाहिए।
  • ✓जब डेवलपर encoder और decoder जोड़ी, पार्सर या सॉर्ट फ़ंक्शन का टेस्ट कर रहा हो।
  • ✓जब डेवलपर fuzzing टूल से Solidity कॉन्ट्रैक्ट का invariant जाँचना चाहता है।

Skill का लिंक

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

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/trailofbits/skills/blob/main/plugins/property-based-testing/skills/property-based-testing/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“मेरे JSON encoder और decoder के लिए property-based टेस्ट लिखिए, जो हर round trip जाँचें।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

यह स्किल कोड में properties पहचानती है, जैसे round trip, idempotence या invariants, और उन्हें बताने वाले टेस्ट लिखती है। यह जाँचती है कि कोड की टेस्ट करने लायक साफ़ बनावट है या नहीं, और न होने पर रीफ़ैक्टरिंग सुझाती है।

तकनीकी सामग्री (मूल 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 सूचीबद्ध हैं।

property क्या है?

यह ऐसा नियम है जो हर वैध इनपुट के लिए सच होना चाहिए, जैसे encode किए मान को decode करने पर मूल मान वापस मिलना।

जानकारी

लेखक का मूल विवरण

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
अपडेट की गई
2/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

audit-context-building

8.0k

यह आपके एजेंट को सुरक्षा जाँच से पहले किसी अनजान कोड को समझने में मदद करती है, हर फ़ंक्शन की मान्यताएँ और निर्भरताएँ नक्शे में दिखाकर।

कोडिंगसिक्योरिटी

algorand-vulnerability-scanner

8.0k

यह आपके एजेंट को Algorand कॉन्ट्रैक्ट्स में 11 आम सुरक्षा समस्याएँ जाँचने में मदद करती है, जैसे रीकीइंग हमले और बिना जाँची फ़ीस।

कोडिंगसिक्योरिटी

audit-prep-assistant

8.0k

यह आपके एजेंट को बाहरी सुरक्षा समीक्षा के लिए कोड तैयार करने में मदद करती है, जैसे स्टैटिक एनालिसिस, टेस्ट कवरेज और दस्तावेज़ीकरण।

कोडिंगसिक्योरिटी

cairo-vulnerability-scanner

8.0k

यह आपके एजेंट को StarkNet के Cairo कॉन्ट्रैक्ट्स में 6 गंभीर समस्याएँ जाँचने में मदद करती है, जैसे ओवरफ़्लो और सिग्नेचर रीप्ले।

कोडिंगसिक्योरिटी

मिलती-जुलती skills