# Build Rust Test Mocks with Trait Patterns

Rust tests often become slow or fragile when they depend on databases, HTTP services, or real infrastructure. This skill helps Claude, Codex, and Claude Code design trait-based mocks, controlled failures, and fixture helpers.

## Install

```bash
npx skillstore add emillindfors/mock-strategy-guide
```

## Metadata

- Status: approved
- Slug: emillindfors-mock-strategy-guide
- Version: 1.0.0
- Author version: 1.0.0
- Skillstore revision: r1
- Version status: valid
- Tree hash: 39dc35dfdaa480937c51c9ca099730543a7b467ea2cd95db5b6b3fc1849c2219
- Author: EmilLindfors
- GitHub username: EmilLindfors
- License: MIT
- Repository: https://github.com/EmilLindfors/claude-marketplace/tree/main/plugins/rust-testing/skills/mock-strategy-guide
- Ref: a06681402992ceae98ba04d54cfd4ab004862696
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands
- Quality score: 81
- Quality tier: silver
- Public page: https://skillstore.pages.dev/skills/emillindfors-mock-strategy-guide
- Manifest: https://skillstore.pages.dev/api/skills/emillindfors-mock-strategy-guide/manifest

## Capabilities

- Explains when to introduce trait-based mocks for external dependencies.
- Shows simple mock repositories for async Rust service tests.
- Demonstrates verification of side effects such as sent email records.
- Provides patterns for controlled success, not-found, and database-error behavior.
- Outlines in-memory repositories and fixture helpers for repeatable tests.

## Use Cases

- Mock a Repository: Design a lightweight repository mock for a Rust service that depends on stored user data.
- Verify Side Effects: Capture calls to an email or notification service and assert that the service behaved correctly.
- Remove Infrastructure From Tests: Replace database or HTTP dependencies with trait abstractions and in-memory test implementations.

## Prompt Templates

### Create a Basic Mock

```
Help me create a simple Rust mock for a trait-based repository. Explain the structure and the test flow.
```

### Add Verification

```
Show me how to design a mock service that records calls so my Rust test can verify side effects.
```

### Model Failure Paths

```
Design a Rust mock strategy that can return success, not-found, and database-error outcomes for service tests.
```

### Refactor for Testability

```
Review this Rust service design and suggest trait boundaries, mock implementations, and fixture helpers for maintainable tests.
```

## Limitations

- Focuses on Rust examples and does not cover every mocking framework.
- Does not run tests or inspect project code without user-provided context.
- Assumes the project can introduce traits around external dependencies.
- Provides guidance, not a complete test suite for an application.

## Best Practices

- Keep mocks small and local to the behavior under test.
- Model expected failures explicitly so tests check error handling.
- Use fixture helpers for shared data, but keep assertions in the test body.

## Anti Patterns

- Using production databases or HTTP services for unit tests.
- Coupling service logic directly to concrete infrastructure clients.
- Writing mocks that hide important errors or accept every input.

## Security Audit

- Audited at: 2026-07-06T15:07:29.602\+00:00
- Summary: All external command findings are false positives caused by Markdown code fences around Rust test examples, not shell or Ruby execution. The obfuscation heuristic is also a false positive; the file contains plain YAML front matter and Rust-oriented documentation. No prompt injection or malicious semantic intent was found.

## Stats

- Views: 136
- Downloads: 9
- Favorites: 0
- Popularity score: 0
