mock-strategy-guide

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.

242 stars

Best use case

mock-strategy-guide is best used when you need a repeatable AI agent workflow instead of a one-off prompt. It is especially useful for teams working in multi. 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.

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.

Users should expect a more consistent workflow output, faster repeated execution, and less time spent rewriting prompts from scratch.

Practical example

Example input

Use the "mock-strategy-guide" skill to help with this workflow task. Context: 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.

Example output

A structured workflow result with clearer steps, more consistent formatting, and an output that is easier to reuse in the next run.

When to use this skill

  • Use this skill when you want a reusable workflow rather than writing the same prompt again and again.

When not to use this skill

  • Do not use this when you only need a one-off answer and do not need a reusable workflow.
  • Do not use it if you cannot install or maintain the related files, repository context, or supporting tools.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/mock-strategy-guide/SKILL.md --create-dirs "https://raw.githubusercontent.com/aiskillstore/marketplace/main/skills/emillindfors/mock-strategy-guide/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/mock-strategy-guide/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How mock-strategy-guide Compares

Feature / Agentmock-strategy-guideStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

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.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# 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 {
        sent_emails: Arc<Mutex<Vec<Email>>>,
    }

    impl MockEmailService {
        fn new() -> Self {
            Self {
                sent_emails: Arc::new(Mutex::new(Vec::new())),
            }
        }

        fn emails_sent(&self) -> Vec<Email> {
            self.sent_emails.lock().unwrap().clone()
        }
    }

    #[async_trait]
    impl EmailService for MockEmailService {
        async fn send(&self, email: Email) -> Result<(), Error> {
            self.sent_emails.lock().unwrap().push(email);
            Ok(())
        }
    }

    #[tokio::test]
    async fn test_sends_welcome_email() {
        let mock_email = MockEmailService::new();
        let service = UserService::new(mock_email.clone());

        service.register_user("test@example.com").await.unwrap();

        // Verify email was sent
        let emails = mock_email.emails_sent();
        assert_eq!(emails.len(), 1);
        assert_eq!(emails[0].to, "test@example.com");
        assert!(emails[0].subject.contains("Welcome"));
    }
}
```

### Pattern 3: Mock with Controlled Failures

```rust
#[cfg(test)]
mod tests {
    enum MockBehavior {
        Success,
        NotFound,
        DatabaseError,
    }

    struct MockRepository {
        behavior: MockBehavior,
    }

    impl MockRepository {
        fn with_behavior(behavior: MockBehavior) -> Self {
            Self { behavior }
        }
    }

    #[async_trait]
    impl UserRepository for MockRepository {
        async fn find(&self, id: &str) -> Result<User, Error> {
            match self.behavior {
                MockBehavior::Success => Ok(test_user()),
                MockBehavior::NotFound => Err(Error::NotFound),
                MockBehavior::DatabaseError => Err(Error::Database("Connection failed".into())),
            }
        }
    }

    #[tokio::test]
    async fn test_handles_not_found() {
        let mock = MockRepository::with_behavior(MockBehavior::NotFound);
        let service = UserService::new(mock);

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

        assert!(result.is_err());
        assert!(matches!(result.unwrap_err(), Error::NotFound));
    }

    #[tokio::test]
    async fn test_handles_database_error() {
        let mock = MockRepository::with_behavior(MockBehavior::DatabaseError);
        let service = UserService::new(mock);

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

        assert!(result.is_err());
    }
}
```

### Pattern 4: Builder Pattern for Mocks

```rust
#[cfg(test)]
mod tests {
    struct MockRepositoryBuilder {
        users: HashMap<String, User>,
        find_error: Option<Error>,
        save_error: Option<Error>,
    }

    impl MockRepositoryBuilder {
        fn new() -> Self {
            Self {
                users: HashMap::new(),
                find_error: None,
                save_error: None,
            }
        }

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

        fn with_find_error(mut self, error: Error) -> Self {
            self.find_error = Some(error);
            self
        }

        fn build(self) -> MockRepository {
            MockRepository {
                users: self.users,
                find_error: self.find_error,
                save_error: self.save_error,
            }
        }
    }

    #[tokio::test]
    async fn test_with_builder() {
        let mock = MockRepositoryBuilder::new()
            .with_user(test_user())
            .with_save_error(Error::Database("Save failed".into()))
            .build();

        let service = UserService::new(mock);

        // Can find user
        let user = service.get_user("1").await.unwrap();

        // But save fails
        let result = service.update_user(user).await;
        assert!(result.is_err());
    }
}
```

## In-Memory Test Implementations

For integration tests with real logic but no infrastructure:

```rust
pub struct InMemoryUserRepository {
    users: Arc<Mutex<HashMap<String, User>>>,
}

impl InMemoryUserRepository {
    pub fn new() -> Self {
        Self {
            users: Arc::new(Mutex::new(HashMap::new())),
        }
    }
}

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

    async fn save(&self, user: &User) -> Result<(), Error> {
        self.users
            .lock()
            .unwrap()
            .insert(user.id.clone(), user.clone());
        Ok(())
    }

    async fn delete(&self, id: &str) -> Result<(), Error> {
        self.users
            .lock()
            .unwrap()
            .remove(id)
            .ok_or(Error::NotFound)?;
        Ok(())
    }
}
```

## Test Fixture Helpers

```rust
#[cfg(test)]
mod fixtures {
    use super::*;

    pub fn test_user() -> User {
        User {
            id: "test-id".to_string(),
            email: "test@example.com".to_string(),
            name: "Test User".to_string(),
        }
    }

    pub fn test_user_with_id(id: &str) -> User {
        User {
            id: id.to_string(),
            email: "test@example.com".to_string(),
            name: "Test User".to_string(),
        }
    }

    pub fn test_users(count: usize) -> Vec<User> {
        (0..count)
            .map(|i| test_user_with_id(&format!("user-{}", i)))
            .collect()
    }
}
```

## Your Approach

When you see code needing tests:
1. Identify external dependencies (traits)
2. Suggest mock implementation structure
3. Show verification patterns
4. Provide test fixture helpers

When you see tests without mocks:
1. Suggest extracting trait if tightly coupled
2. Show how to create mock implementations
3. Demonstrate verification patterns

Proactively suggest mocking strategies for testable, maintainable code.

Related Skills

google-official-seo-guide

242
from aiskillstore/marketplace

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

opensource-guide-coach

242
from aiskillstore/marketplace

Use when a user wants guidance on starting, contributing to, growing, governing, funding, securing, or sustaining an open source project, or asks about contributor onboarding, community health, maintainer burnout, code of conduct, metrics, legal basics, or open source project adoption.

woocommerce-copy-guidelines

242
from aiskillstore/marketplace

Guidelines for UI text and copy in WooCommerce. Use when writing user-facing text, labels, buttons, or messages.

vue-development-guides

242
from aiskillstore/marketplace

A collection of best practices and tips for developing applications using Vue.js. This skill MUST be apply when developing, refactoring or reviewing Vue.js or Nuxt projects.

user-guide-writing

242
from aiskillstore/marketplace

Write clear and helpful user guides and tutorials for end users. Use when creating onboarding docs, how-to guides, or FAQ pages. Handles user-focused documentation, screenshots, step-by-step instructions.

environment-setup-guide

242
from aiskillstore/marketplace

Guide developers through setting up development environments with proper tools, dependencies, and configurations

cc-skill-project-guidelines-example

242
from aiskillstore/marketplace

Project Guidelines Skill (Example)

brand-guidelines-community

242
from aiskillstore/marketplace

Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatt...

brand-guidelines-anthropic

242
from aiskillstore/marketplace

Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatt...

api-testing-observability-api-mock

242
from aiskillstore/marketplace

You are an API mocking expert specializing in realistic mock services for development, testing, and demos. Design mocks that simulate real API behavior and enable parallel development.

skill-creation-guide

242
from aiskillstore/marketplace

Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.

video-prompting-guide

242
from aiskillstore/marketplace

Best practices and techniques for writing effective AI video generation prompts. Covers: Veo, Seedance, Wan, Grok, Kling, Runway, Pika, Sora prompting strategies. Learn: shot types, camera movements, lighting, pacing, style keywords, negative prompts. Use for: improving video quality, getting consistent results, professional video prompts. Triggers: video prompt, how to prompt video, veo prompts, video generation tips, better ai video, video prompt engineering, video prompt guide, video prompt template, ai video tips, video prompt best practices, video prompt examples, cinematography prompts