Jeffallan/claude-skills / skills/test-master
test-master
VerifiedGenerates test files, creates mocking strategies, analyzes code coverage, designs test architectures, and produces test plans and defect reports across functional, performance, and security testing disciplines. Use when writing unit tests, integration tests, or E2E tests; creating test strategies or automation frameworks; analyzing coverage gaps; performance testing with k6 or Artillery; security testing with OWASP methods; debugging flaky tests; or working on QA, regression, test automation, quality gates, shift-left testing, or test maintenance.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 5.1 KB |
| references/automation-frameworks.md | markdown | 7.2 KB |
| references/e2e-testing.md | markdown | 4.8 KB |
| references/integration-testing.md | markdown | 2.7 KB |
| references/performance-testing.md | markdown | 2.6 KB |
| references/qa-methodology.md | markdown | 6.2 KB |
| references/security-testing.md | markdown | 3.3 KB |
| references/tdd-iron-laws.md | markdown | 4.3 KB |
| references/test-reports.md | markdown | 2.3 KB |
| references/testing-anti-patterns.md | markdown | 6.4 KB |
| references/unit-testing.md | markdown | 2.7 KB |
references/unit-testing.md
View on GitHub# Unit Testing
## Jest/Vitest Pattern
```typescript
describe('UserService', () => {
let service: UserService;
let mockRepo: jest.Mocked<UserRepository>;
beforeEach(() => {
mockRepo = { findById: jest.fn(), save: jest.fn() } as any;
service = new UserService(mockRepo);
});
afterEach(() => jest.clearAllMocks());
describe('getUser', () => {
it('returns user when found', async () => {
const user = { id: '1', name: 'Test' };
mockRepo.findById.mockResolvedValue(user);
const result = await service.getUser('1');
expect(result).toEqual(user);
expect(mockRepo.findById).toHaveBeenCalledWith('1');
});
it('throws NotFoundError when user not found', async () => {
mockRepo.findById.mockResolvedValue(null);
await expect(service.getUser('1')).rejects.toThrow(NotFoundError);
});
});
});
```
## pytest Pattern
```python
import pytest
from unittest.mock import Mock, AsyncMock
class TestUserService:
@pytest.fixture
def mock_repo(self):
return Mock()
@pytest.fixture
def service(self, mock_repo):
return UserService(mock_repo)
async def test_get_user_returns_user(self, service, mock_repo):
mock_repo.find_by_id = AsyncMock(return_value={"id": "1", "name": "Test"})
result = await service.get_user("1")
assert result == {"id": "1", "name": "Test"}
mock_repo.find_by_id.assert_called_once_with("1")
async def test_get_user_raises_not_found(self, service, mock_repo):
mock_repo.find_by_id = AsyncMock(return_value=None)
with pytest.raises(NotFoundError):
await service.get_user("1")
```
## Mocking Patterns
```typescript
// Mock functions
const mockFn = jest.fn();
mockFn.mockReturnValue('value');
mockFn.mockResolvedValue('async value');
mockFn.mockRejectedValue(new Error('error'));
// Mock modules
jest.mock('./database', () => ({
query: jest.fn(),
}));
// Spy on existing methods
jest.spyOn(console, 'log').mockImplementation(() => {});
```
## Test Organization
```typescript
describe('Feature', () => {
describe('happy path', () => {
it('does expected behavior', () => {});
});
describe('edge cases', () => {
it('handles empty input', () => {});
it('handles max values', () => {});
});
describe('error cases', () => {
it('throws on invalid input', () => {});
});
});
```
## Quick Reference
| Pattern | Use Case |
|---------|----------|
| `describe()` | Group related tests |
| `it()` / `test()` | Single test case |
| `beforeEach()` | Setup before each test |
| `jest.fn()` | Create mock function |
| `mockResolvedValue()` | Mock async return |
| `expect().toThrow()` | Assert exception |
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |