一键导入
testing
Write comprehensive test suites with unit tests, integration tests, assertions, mocking, edge case coverage, and test-driven development patterns
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Write comprehensive test suites with unit tests, integration tests, assertions, mocking, edge case coverage, and test-driven development patterns
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Evaluate workflow run quality by analyzing artifacts and scratch outputs, identify gaps and root causes, and write a structured assessment with actionable recommendations.
Write an Architecture Decision Record (ADR) for a technical decision
Diagnose a bug, identify root cause, implement a targeted fix, and verify it
Analyze requirements and produce a detailed implementation plan before writing code
Create a GitHub branch, commit changes to it, and open a pull request
Explore a newly-loaded workspace, map its structure, and write project notes to memory
| name | testing |
| description | Write comprehensive test suites with unit tests, integration tests, assertions, mocking, edge case coverage, and test-driven development patterns |
This skill enables writing comprehensive test suites that cover unit tests, integration tests, assertions, mocking, edge case coverage, and test-driven development patterns. Build reliable, maintainable code through systematic testing strategies.
const assert = (condition, message) => {
if (!condition) throw new Error(`Assertion failed: ${message}`);
};
const describe = (suite, fn) => {
console.log(`📋 ${suite}`);
try { fn(); } catch (e) { console.error(` ❌ ${e.message}`); }
};
const it = (test, fn) => {
try {
fn();
console.log(` ✓ ${test}`);
} catch (e) {
console.error(` ✗ ${test}: ${e.message}`);
}
};
// Usage:
describe('Calculator', () => {
it('adds numbers correctly', () => {
const result = add(2, 3);
assert(result === 5, 'Expected 2 + 3 to equal 5');
});
it('handles negative numbers', () => {
const result = add(-2, 3);
assert(result === 1, 'Expected -2 + 3 to equal 1');
});
it('handles zero', () => {
const result = add(0, 0);
assert(result === 0, 'Expected 0 + 0 to equal 0');
});
});
const createMock = () => {
const mock = function(...args) {
mock.calls.push(args);
return mock.returnValue;
};
mock.calls = [];
mock.returnValue = undefined;
mock.returns = (value) => { mock.returnValue = value; return mock; };
mock.calledWith = (...args) => mock.calls.some(c => JSON.stringify(c) === JSON.stringify(args));
mock.callCount = () => mock.calls.length;
return mock;
};
// Usage:
const fetchMock = createMock().returns(Promise.resolve({ data: 'test' }));
await fetchMock();
assert(fetchMock.callCount() === 1, 'fetch should be called once');
assert(fetchMock.calledWith(), 'fetch should be called');
const testIntegration = async () => {
// Setup: Create isolated test environment
const testDb = createMemoryDb();
const service = createService(testDb);
// Act: Execute integrated behavior
const user = await service.createUser({ name: 'Test', email: 'test@example.com' });
const retrieved = await service.getUser(user.id);
// Assert: Verify end-to-end behavior
assert(retrieved.name === 'Test', 'User name should persist');
assert(retrieved.email === 'test@example.com', 'User email should persist');
// Cleanup
await testDb.close();
};
describe('String Utils', () => {
describe('trim()', () => {
// Happy path
it('removes leading and trailing whitespace', () => {
assert(trim(' hello ') === 'hello');
});
// Edge cases
it('handles empty string', () => {
assert(trim('') === '');
});
it('handles string with only whitespace', () => {
assert(trim(' ') === '');
});
it('handles strings with tabs and newlines', () => {
assert(trim('\t hello \n') === 'hello');
});
it('handles single character', () => {
assert(trim(' a ') === 'a');
});
it('preserves internal whitespace', () => {
assert(trim(' hello world ') === 'hello world');
});
// Boundary conditions
it('handles very long strings', () => {
const long = ' ' + 'x'.repeat(10000) + ' ';
assert(trim(long) === 'x'.repeat(10000));
});
});
});
it('should fetch user data', async () => {
const user = await fetchUser(1);
assert(user.id === 1, 'Should return correct user');
});
it('should handle fetch errors', async () => {
try {
await fetchUser(-1);
assert(false, 'Should have thrown error');
} catch (e) {
assert(e.message.includes('not found'), 'Should be 404 error');
}
});
it('should render button with correct text', () => {
const html = Button({ label: 'Save' });
assert(html.includes('<button'), 'Should render button element');
assert(html.includes('Save'), 'Should include button text');
});
it('should apply CSS class', () => {
const html = Button({ class: 'primary' });
assert(html.includes('class="primary"'), 'Should have primary class');
});
const createUserService = (database) => ({
create: async (user) => database.insert('users', user),
get: async (id) => database.query('users', { id })
});
it('should create and retrieve user', async () => {
const dbMock = { insert: createMock(), query: createMock().returns(Promise.resolve({ id: 1, name: 'Test' })) };
const service = createUserService(dbMock);
await service.create({ name: 'Test' });
assert(dbMock.insert.calledWith('users'), 'Should call database insert');
});
// Simple test runner
const runTests = async (testFiles) => {
let passed = 0, failed = 0;
for (const file of testFiles) {
const tests = await import(file);
if (tests.default) await tests.default();
}
console.log(`\n✓ ${passed} passed, ✗ ${failed} failed`);
};