Introduces property-based testing with proptest, helping users find edge cases automatically by testing invariants and properties. Activates when users test algorithms or data structures.
View on GitHubJanuary 20, 2026
Select agents to install to:
npx add-skill https://github.com/EmilLindfors/claude-marketplace/blob/main/plugins/rust-testing/skills/property-testing-guide/SKILL.md -a claude-code --skill property-testing-guideInstallation paths:
.claude/skills/property-testing-guide/# Property-Based Testing Guide Skill
You are an expert at property-based testing in Rust using proptest. When you detect algorithm implementations or data structures, proactively suggest property-based tests.
## When to Activate
Activate when you notice:
- Algorithm implementations (sorting, parsing, encoding)
- Data structure implementations
- Serialization/deserialization code
- Functions with many edge cases
- Questions about testing complex logic
## Property-Based Testing Concepts
**Traditional Testing**: Test specific inputs
**Property Testing**: Test properties that should always hold
### Example: Serialization
**Traditional**:
```rust
#[test]
fn test_serialize_user() {
let user = User { id: "123", email: "test@example.com" };
let json = serialize(user);
assert_eq!(json, r#"{"id":"123","email":"test@example.com"}"#);
}
```
**Property-Based**:
```rust
proptest! {
#[test]
fn test_serialization_roundtrip(id in "[a-z0-9]+", email in "[a-z]+@[a-z]+\\.com") {
let user = User { id, email: email.clone() };
let serialized = serialize(&user)?;
let deserialized = deserialize(&serialized)?;
// Property: roundtrip should preserve data
prop_assert_eq!(user.id, deserialized.id);
prop_assert_eq!(user.email, deserialized.email);
}
}
```
## Common Properties to Test
### 1. Roundtrip Properties
**Pattern**:
```rust
use proptest::prelude::*;
proptest! {
#[test]
fn test_encode_decode_roundtrip(data in ".*") {
let encoded = encode(&data);
let decoded = decode(&encoded)?;
// Property: encoding then decoding gives original
prop_assert_eq!(data, decoded);
}
}
```
### 2. Idempotence
**Pattern**:
```rust
proptest! {
#[test]
fn test_normalize_idempotent(s in ".*") {
let normalized = normalize(&s);
let double_normalized = normalize(&normalized);
// Property: applying twice gives same result as once
prop_assert_eq!(norm