skills_all/testing-code/SKILL.md
Write automated tests for features, validate functionality against acceptance criteria, and ensure code coverage. Use when writing test code, verifying functionality, or adding test coverage to existing code.
npx skillsauth add activer007/ordinary-claude-skills Testing CodeInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Test writing follows a systematic approach: determine scope, understand patterns, map to requirements, write tests, verify coverage.
Read project documentation:
docs/user-stories/US-###-*.md for acceptance criteria to testdocs/feature-spec/F-##-*.md for technical requirementsdocs/api-contracts.yaml for API specificationsChoose test types needed:
Investigate current test approach:
Use code-finder agents if unfamiliar with test structure.
Convert 3-5 acceptance criteria to specific test cases across test types:
Example mapping:
## User Story: US-101 User Login
### Test Cases
1. **Unit: Authentication service**
- validateCredentials() returns true for valid email/password
- validateCredentials() returns false for invalid password
- checkAccountStatus() detects locked accounts
2. **Integration: Login endpoint**
- POST /api/login with valid creds returns 200 + token
- POST /api/login with invalid creds returns 401 + error
- POST /api/login with locked account returns 403
3. **Component: Login form**
- Submitting form calls login API
- Error message displays on 401 response
- Success redirects to /dashboard
4. **E2E: Complete login flow**
- User enters credentials → submits → sees dashboard
- User enters wrong password → sees error → retries successfully
Unit Test Structure:
describe('AuthService', () => {
describe('validateCredentials', () => {
it('returns true for valid email and password', async () => {
const result = await authService.validateCredentials(
'[email protected]',
'ValidPass123'
);
expect(result).toBe(true);
});
it('returns false for invalid password', async () => {
const result = await authService.validateCredentials(
'[email protected]',
'WrongPassword'
);
expect(result).toBe(false);
});
});
});
Integration Test Structure:
describe('POST /api/auth/login', () => {
beforeEach(async () => {
await resetTestDatabase();
await createTestUser({
email: '[email protected]',
password: 'Test123!'
});
});
it('returns 200 and token for valid credentials', async () => {
const response = await request(app)
.post('/api/auth/login')
.send({ email: '[email protected]', password: 'Test123!' });
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('token');
expect(response.body.token).toMatch(/^eyJ/); // JWT format
});
it('returns 401 for invalid password', async () => {
const response = await request(app)
.post('/api/auth/login')
.send({ email: '[email protected]', password: 'WrongPassword' });
expect(response.status).toBe(401);
expect(response.body.error).toBe('Invalid credentials');
});
});
Component Test Structure:
describe('LoginForm', () => {
it('submits form with valid data', async () => {
const mockLogin = jest.fn().mockResolvedValue({ success: true });
render(<LoginForm onLogin={mockLogin} />);
await userEvent.type(screen.getByLabelText(/email/i), '[email protected]');
await userEvent.type(screen.getByLabelText(/password/i), 'Password123');
await userEvent.click(screen.getByRole('button', { name: /log in/i }));
expect(mockLogin).toHaveBeenCalledWith({
email: '[email protected]',
password: 'Password123'
});
});
it('displays error message on API failure', async () => {
const mockLogin = jest.fn().mockRejectedValue(new Error('Invalid credentials'));
render(<LoginForm onLogin={mockLogin} />);
await userEvent.type(screen.getByLabelText(/email/i), '[email protected]');
await userEvent.type(screen.getByLabelText(/password/i), 'wrong');
await userEvent.click(screen.getByRole('button', { name: /log in/i }));
expect(await screen.findByText(/invalid credentials/i)).toBeInTheDocument();
});
});
E2E Test Structure:
test('user can log in successfully', async ({ page }) => {
await page.goto('/login');
await page.fill('[name="email"]', '[email protected]');
await page.fill('[name="password"]', 'Test123!');
await page.click('button:has-text("Log In")');
await page.waitForURL('/dashboard');
expect(page.url()).toContain('/dashboard');
});
Include boundary conditions and error paths:
describe('Edge cases', () => {
it('handles empty email gracefully', async () => {
await expect(
authService.validateCredentials('', 'password')
).rejects.toThrow('Email is required');
});
it('handles extremely long password', async () => {
const longPassword = 'a'.repeat(10000);
await expect(
authService.validateCredentials('[email protected]', longPassword)
).rejects.toThrow('Password too long');
});
it('handles network timeout', async () => {
jest.spyOn(global, 'fetch').mockImplementation(
() => new Promise((resolve) => setTimeout(resolve, 10000))
);
await expect(
authService.login('[email protected]', 'pass')
).rejects.toThrow('Request timeout');
});
});
Edge cases to always include:
Create reusable test fixtures:
// tests/fixtures/users.ts
export const validUser = {
email: '[email protected]',
password: 'Test123!',
name: 'Test User'
};
export const invalidUsers = {
noEmail: { password: 'Test123!' },
noPassword: { email: '[email protected]' },
invalidEmail: { email: 'not-an-email', password: 'Test123!' },
weakPassword: { email: '[email protected]', password: '123' }
};
// Use in tests
import { validUser, invalidUsers } from './fixtures/users';
it('validates user data', () => {
expect(validate(validUser)).toBe(true);
expect(validate(invalidUsers.noEmail)).toBe(false);
});
When tests are independent (different modules, different test types), spawn parallel agents:
Pattern 1: Layer-based
Pattern 2: Feature-based
Pattern 3: Type-based
Execute test suite:
# Unit tests
npm test -- --coverage
# Integration tests
npm run test:integration
# E2E tests
npm run test:e2e
# All tests
npm run test:all
Verify coverage:
Coverage:
Structure:
Data:
Integration:
tools
Generate typed TypeScript SDKs for AI agents to interact with MCP servers. Converts verbose JSON-RPC curl commands to clean function calls (docs.createDocument() vs curl). Auto-detects MCP tools from server modules, generates TypeScript types and client methods, creates runnable example scripts. Use when: building MCP-enabled applications, need typed programmatic access to MCP tools, want Claude Code to manage apps via scripts, eliminating manual JSON-RPC curl commands, validating MCP inputs/outputs, or creating reusable agent automation.
testing
Generate structured task lists from specs or requirements. IMPORTANT: After completing ANY spec via ExitSpecMode, ALWAYS ask the user: "Would you like me to generate a task list for this spec?" Use when user confirms or explicitly requests task generation from a plan/spec/PRD.
tools
Create compelling story-format summaries using UltraThink to find the best narrative framing. Support multiple formats - 3-part narrative, n-length with inline links, abridged 5-line, or comprehensive via Foundry MCP. USE WHEN user says 'create story explanation', 'narrative summary', 'explain as a story', or wants content in Daniel's conversational first-person voice.
testing
Navigate through the original three-world shamanic technology. Deploy when soul retrieval, power animal guidance, or journey between realms emerges. Deeply respectful of Tungus, Buryat, Yakut, Evenki traditions. Use for consciousness navigation, NOT cultural appropriation.