Initial commit
This commit is contained in:
15
.claude-plugin/plugin.json
Normal file
15
.claude-plugin/plugin.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "test-doubles-generator",
|
||||
"description": "Generate mocks, stubs, spies, and fakes for unit testing with Jest, Sinon, and test frameworks",
|
||||
"version": "1.0.0",
|
||||
"author": {
|
||||
"name": "Claude Code Plugin Hub",
|
||||
"email": "[email protected]"
|
||||
},
|
||||
"skills": [
|
||||
"./skills"
|
||||
],
|
||||
"commands": [
|
||||
"./commands"
|
||||
]
|
||||
}
|
||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# test-doubles-generator
|
||||
|
||||
Generate mocks, stubs, spies, and fakes for unit testing with Jest, Sinon, and test frameworks
|
||||
130
commands/gen-doubles.md
Normal file
130
commands/gen-doubles.md
Normal file
@@ -0,0 +1,130 @@
|
||||
---
|
||||
description: Generate test doubles (mocks, stubs, spies, fakes) for unit testing
|
||||
shortcut: gd
|
||||
---
|
||||
|
||||
# Test Doubles Generator
|
||||
|
||||
Generate appropriate test doubles (mocks, stubs, spies, fakes, dummies) for unit testing based on the testing framework and dependencies being tested.
|
||||
|
||||
## What You Do
|
||||
|
||||
1. **Analyze Dependencies**
|
||||
- Identify external dependencies in code under test
|
||||
- Determine appropriate test double type for each
|
||||
- Generate test doubles with proper behavior
|
||||
|
||||
2. **Generate Mocks**
|
||||
- Create mock implementations with verification
|
||||
- Set up method expectations and return values
|
||||
- Configure mock behavior for test scenarios
|
||||
|
||||
3. **Generate Stubs**
|
||||
- Create stub implementations with predefined responses
|
||||
- Handle edge cases and error conditions
|
||||
- Provide test data fixtures
|
||||
|
||||
4. **Generate Spies**
|
||||
- Wrap real implementations with call tracking
|
||||
- Capture arguments and return values
|
||||
- Enable behavior verification
|
||||
|
||||
## Usage Pattern
|
||||
|
||||
When invoked, you should:
|
||||
|
||||
1. Analyze the code file or function to be tested
|
||||
2. Identify all dependencies (APIs, databases, services, etc.)
|
||||
3. Recommend appropriate test double type for each dependency
|
||||
4. Generate test doubles with realistic behavior
|
||||
5. Provide example test cases using the doubles
|
||||
6. Include setup and teardown code
|
||||
|
||||
## Output Format
|
||||
|
||||
```markdown
|
||||
## Test Doubles Generated for: [Component]
|
||||
|
||||
### Dependencies Identified: [N]
|
||||
|
||||
#### Dependency: [Name]
|
||||
**Type:** [API / Database / Service / File System]
|
||||
**Test Double:** [Mock / Stub / Spy / Fake]
|
||||
**Rationale:** [Why this type]
|
||||
|
||||
**Implementation:**
|
||||
|
||||
\`\`\`javascript
|
||||
// Mock for [Name]
|
||||
const mock[Name] = {
|
||||
methodName: jest.fn()
|
||||
.mockResolvedValueOnce([success response])
|
||||
.mockRejectedValueOnce(new Error('[error]')),
|
||||
|
||||
anotherMethod: jest.fn().mockReturnValue([value])
|
||||
};
|
||||
\`\`\`
|
||||
|
||||
**Usage in Tests:**
|
||||
|
||||
\`\`\`javascript
|
||||
describe('[Component]', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should [behavior]', async () => {
|
||||
// Arrange
|
||||
mock[Name].methodName.mockResolvedValue([data]);
|
||||
|
||||
// Act
|
||||
const result = await componentUnderTest.action();
|
||||
|
||||
// Assert
|
||||
expect(mock[Name].methodName).toHaveBeenCalledWith([expected args]);
|
||||
expect(result).toEqual([expected result]);
|
||||
});
|
||||
|
||||
it('should handle errors', async () => {
|
||||
// Arrange
|
||||
mock[Name].methodName.mockRejectedValue(new Error('[error]'));
|
||||
|
||||
// Act & Assert
|
||||
await expect(componentUnderTest.action()).rejects.toThrow('[error]');
|
||||
});
|
||||
});
|
||||
\`\`\`
|
||||
|
||||
### Test Data Fixtures
|
||||
|
||||
\`\`\`javascript
|
||||
const fixtures = {
|
||||
validData: { /* ... */ },
|
||||
invalidData: { /* ... */ },
|
||||
edgeCases: { /* ... */ }
|
||||
};
|
||||
\`\`\`
|
||||
|
||||
### Next Steps
|
||||
- [ ] Implement generated test doubles
|
||||
- [ ] Write test cases using doubles
|
||||
- [ ] Verify test coverage
|
||||
- [ ] Refactor for reusability
|
||||
```
|
||||
|
||||
## Test Double Types
|
||||
|
||||
**Mock**: Behavior verification, tracks calls and arguments
|
||||
**Stub**: State verification, returns predefined responses
|
||||
**Spy**: Wraps real object, tracks interactions
|
||||
**Fake**: Working implementation with shortcuts (in-memory DB)
|
||||
**Dummy**: Placeholder objects, not used in test
|
||||
|
||||
## Framework Support
|
||||
|
||||
- Jest (JavaScript/TypeScript)
|
||||
- Sinon.js (JavaScript)
|
||||
- unittest.mock (Python)
|
||||
- Mockito (Java)
|
||||
- Moq (.NET)
|
||||
- RSpec mocks (Ruby)
|
||||
61
plugin.lock.json
Normal file
61
plugin.lock.json
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"$schema": "internal://schemas/plugin.lock.v1.json",
|
||||
"pluginId": "gh:jeremylongshore/claude-code-plugins-plus:plugins/testing/test-doubles-generator",
|
||||
"normalized": {
|
||||
"repo": null,
|
||||
"ref": "refs/tags/v20251128.0",
|
||||
"commit": "bc65efc4fd7438589bc8b55a845af8cfae934002",
|
||||
"treeHash": "8448ae454ce11a7d84658ec2593b2083fecd74ff89c756e59d2b1fdcd0b27b97",
|
||||
"generatedAt": "2025-11-28T10:18:49.191701Z",
|
||||
"toolVersion": "publish_plugins.py@0.2.0"
|
||||
},
|
||||
"origin": {
|
||||
"remote": "git@github.com:zhongweili/42plugin-data.git",
|
||||
"branch": "master",
|
||||
"commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390",
|
||||
"repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data"
|
||||
},
|
||||
"manifest": {
|
||||
"name": "test-doubles-generator",
|
||||
"description": "Generate mocks, stubs, spies, and fakes for unit testing with Jest, Sinon, and test frameworks",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"content": {
|
||||
"files": [
|
||||
{
|
||||
"path": "README.md",
|
||||
"sha256": "62b36ad9f7fea1de3a44e26dde72c42ebeb5a4e01f26eab1dc2c1cd9e1ffe4a7"
|
||||
},
|
||||
{
|
||||
"path": ".claude-plugin/plugin.json",
|
||||
"sha256": "e6935fcb548f4ff83720df1367a6927b4f3e57b6b0ec348738a49f0b7b46cab6"
|
||||
},
|
||||
{
|
||||
"path": "commands/gen-doubles.md",
|
||||
"sha256": "aa624aba76c696a7d6bc77cc624e443415e3713bb0776eceddff613bdca6a7b1"
|
||||
},
|
||||
{
|
||||
"path": "skills/test-doubles-generator/SKILL.md",
|
||||
"sha256": "27a9f6c970fe2f99e7973d6a3a9ff9cbd4a1ccd717fa9dfe7891e40c7883f80d"
|
||||
},
|
||||
{
|
||||
"path": "skills/test-doubles-generator/references/README.md",
|
||||
"sha256": "710d63269820ceaafecac992fba05e0ebad739f52b2ea3d4421d4732f6da85ac"
|
||||
},
|
||||
{
|
||||
"path": "skills/test-doubles-generator/scripts/README.md",
|
||||
"sha256": "bd41433a034167e8278a7f48c7dd1a54601a5caed8317593a24f3306e4c6aae8"
|
||||
},
|
||||
{
|
||||
"path": "skills/test-doubles-generator/assets/README.md",
|
||||
"sha256": "93c898bd202b95e4ecd57763dfb949f266b1ae53bf448387c28baf30268f0051"
|
||||
}
|
||||
],
|
||||
"dirSha256": "8448ae454ce11a7d84658ec2593b2083fecd74ff89c756e59d2b1fdcd0b27b97"
|
||||
},
|
||||
"security": {
|
||||
"scannedAt": null,
|
||||
"scannerVersion": null,
|
||||
"flags": []
|
||||
}
|
||||
}
|
||||
52
skills/test-doubles-generator/SKILL.md
Normal file
52
skills/test-doubles-generator/SKILL.md
Normal file
@@ -0,0 +1,52 @@
|
||||
---
|
||||
name: generating-test-doubles
|
||||
description: |
|
||||
This skill uses the test-doubles-generator plugin to automatically create mocks, stubs, spies, and fakes for unit testing. It analyzes dependencies in the code and generates appropriate test doubles based on the chosen testing framework, such as Jest, Sinon, or others. Use this skill when you need to generate test doubles, mocks, stubs, spies, or fakes to isolate units of code during testing. Trigger this skill by requesting test double generation or using the `/gen-doubles` or `/gd` command.
|
||||
allowed-tools: Read, Write, Edit, Grep, Glob, Bash
|
||||
version: 1.0.0
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
This skill empowers Claude to streamline unit testing by automatically generating test doubles (mocks, stubs, spies, and fakes). It analyzes the code under test, identifies dependencies, and creates the necessary test doubles, significantly reducing the time and effort required to write effective unit tests.
|
||||
|
||||
## How It Works
|
||||
|
||||
1. **Dependency Analysis**: Claude analyzes the code to identify dependencies that need to be replaced with test doubles.
|
||||
2. **Test Double Generation**: Based on the dependencies and specified testing framework, Claude generates appropriate test doubles (mocks, stubs, spies, or fakes).
|
||||
3. **Code Insertion**: Claude provides the generated test double code, ready for integration into your unit tests.
|
||||
|
||||
## When to Use This Skill
|
||||
|
||||
This skill activates when you need to:
|
||||
- Create mocks for external API calls in a unit test.
|
||||
- Generate stubs for service dependencies to control their behavior.
|
||||
- Implement spies to track interactions with real objects during testing.
|
||||
|
||||
## Examples
|
||||
|
||||
### Example 1: Generating Mocks for API Calls
|
||||
|
||||
User request: "Generate mocks for the `fetchData` function in `dataService.js` using Jest."
|
||||
|
||||
The skill will:
|
||||
1. Analyze the `dataService.js` file to identify the `fetchData` function and its dependencies.
|
||||
2. Generate a Jest mock for `fetchData`, allowing you to simulate API responses.
|
||||
|
||||
### Example 2: Creating Stubs for Service Dependencies
|
||||
|
||||
User request: "Create stubs for the `NotificationService` in `userService.js` using Sinon."
|
||||
|
||||
The skill will:
|
||||
1. Analyze `userService.js` and identify the `NotificationService` dependency.
|
||||
2. Generate a Sinon stub for `NotificationService`, enabling you to control its behavior during testing of `userService.js`.
|
||||
|
||||
## Best Practices
|
||||
|
||||
- **Framework Selection**: Specify the testing framework you are using (e.g., Jest, Sinon) for optimal test double generation.
|
||||
- **Code Context**: Provide the relevant code snippets or file paths to ensure accurate dependency analysis.
|
||||
- **Test Double Type**: Consider the purpose of the test double. Use mocks for behavior verification, stubs for controlled responses, and spies for interaction tracking.
|
||||
|
||||
## Integration
|
||||
|
||||
This skill integrates directly with your codebase by providing generated test double code snippets that can be easily copied and pasted into your unit tests. It supports popular testing frameworks and enhances the overall testing workflow.
|
||||
7
skills/test-doubles-generator/assets/README.md
Normal file
7
skills/test-doubles-generator/assets/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Assets
|
||||
|
||||
Bundled resources for test-doubles-generator skill
|
||||
|
||||
- [ ] test_double_templates/: Directory containing templates for generating different types of test doubles (mocks, stubs, spies, fakes) for various frameworks.
|
||||
- [ ] example_tests/: Directory containing example test cases demonstrating the usage of generated test doubles.
|
||||
- [ ] configuration_templates/: Templates for configuring the test double generation process.
|
||||
8
skills/test-doubles-generator/references/README.md
Normal file
8
skills/test-doubles-generator/references/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# References
|
||||
|
||||
Bundled resources for test-doubles-generator skill
|
||||
|
||||
- [ ] jest_mocking_guide.md: Comprehensive guide on using Jest for mocking and test double creation.
|
||||
- [ ] sinon_stubbing_guide.md: Detailed documentation on Sinon's stubbing capabilities.
|
||||
- [ ] test_double_best_practices.md: Best practices for creating and using test doubles effectively.
|
||||
- [ ] dependency_analysis_techniques.md: Advanced techniques for analyzing code dependencies.
|
||||
7
skills/test-doubles-generator/scripts/README.md
Normal file
7
skills/test-doubles-generator/scripts/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Scripts
|
||||
|
||||
Bundled resources for test-doubles-generator skill
|
||||
|
||||
- [ ] generate_doubles.py: Script to automate the test double generation process based on user input and code analysis.
|
||||
- [ ] framework_adapter.py: Adapts the core generation logic to different testing frameworks (Jest, Sinon, etc.).
|
||||
- [ ] dependency_analyzer.py: Analyzes code dependencies to determine the appropriate test double types.
|
||||
Reference in New Issue
Block a user