Back to Skills

mock-strategy-guide

verified

Guides users on creating mock implementations for testing with traits, providing test doubles, and avoiding tight coupling to test infrastructure. Activates when users need to test code with external dependencies.

View on GitHub

Marketplace

lf-marketplace

EmilLindfors/claude-marketplace

Plugin

rust-testing

development

Repository

EmilLindfors/claude-marketplace
2stars

plugins/rust-testing/skills/mock-strategy-guide/SKILL.md

Last Verified

January 20, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/EmilLindfors/claude-marketplace/blob/main/plugins/rust-testing/skills/mock-strategy-guide/SKILL.md -a claude-code --skill mock-strategy-guide

Installation paths:

Claude
.claude/skills/mock-strategy-guide/
Powered by add-skill CLI

Instructions

# Mock Strategy Guide Skill

You are an expert at testing strategies for Rust, especially creating mock implementations for hexagonal architecture. When you detect testing needs for code with dependencies, proactively suggest mocking strategies.

## When to Activate

Activate when you notice:
- Code with external dependencies (DB, HTTP, etc.)
- Trait-based abstractions for repositories or services
- Tests that require real infrastructure
- Questions about mocking or test doubles

## Mock Implementation Patterns

### Pattern 1: Simple Mock Repository

```rust
#[cfg(test)]
mod tests {
    use super::*;
    use std::collections::HashMap;

    struct MockUserRepository {
        users: HashMap<String, User>,
    }

    impl MockUserRepository {
        fn new() -> Self {
            Self {
                users: HashMap::new(),
            }
        }

        fn with_user(mut self, user: User) -> Self {
            self.users.insert(user.id.clone(), user);
            self
        }
    }

    #[async_trait]
    impl UserRepository for MockUserRepository {
        async fn find(&self, id: &str) -> Result<User, Error> {
            self.users
                .get(id)
                .cloned()
                .ok_or(Error::NotFound)
        }

        async fn save(&self, user: &User) -> Result<(), Error> {
            // Mock just succeeds
            Ok(())
        }
    }

    #[tokio::test]
    async fn test_user_service() {
        // Arrange
        let user = User { id: "1".to_string(), email: "test@example.com".to_string() };
        let mock_repo = MockUserRepository::new().with_user(user.clone());
        let service = UserService::new(mock_repo);

        // Act
        let result = service.get_user("1").await;

        // Assert
        assert!(result.is_ok());
        assert_eq!(result.unwrap().id, "1");
    }
}
```

### Pattern 2: Mock with Verification

```rust
#[cfg(test)]
mod tests {
    use std::sync::{Arc, Mutex};

    struct MockEmailService {
       

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
6217 chars