← ClaudeAtlas

mock-strategy-guidelisted

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.
aiskillstore/marketplace · ★ 329 · Testing & QA · score 82
Install: claude install-skill aiskillstore/marketplace
# 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"