write-tests
Write comprehensive, principled tests for code.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Write comprehensive, principled tests for code.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
This skill should be used when the user asks about libraries, frameworks, API references, or needs code examples. Activates for setup questions, code generation involving libraries, or mentions of specific frameworks like React, Vue, Next.js, Prisma, Supabase, etc.
Respond to code review comments point by point, quoting each reviewer point verbatim and answering directly beneath it.
Use when moving local sessions between Claude Code and Codex, converting Claude Code JSONL into Codex rollout format, converting Codex rollout JSONL into Claude scrollback, or debugging cross-agent resume state.
Use when moving local sessions between Codex and Claude Code, converting Codex rollout JSONL into Claude scrollback, converting Claude Code JSONL into Codex rollout format, or debugging cross-agent resume state.
Operate remote hosts over SSH through the ssh-mcp server, driving a box like a person at a terminal instead of firing blind one-off commands.
Use when a task involves SSH or a remote host, including remote commands, interactive shells, sudo over SSH, tailing logs, deployments, scp or rsync file transfer, and port forwards or tunnels.
| name | write-tests |
| description | Write comprehensive, principled tests for code. |
| when_to_use | Use when the user asks to write tests, add tests, create a test suite, test a file/function/module, or improve coverage. |
| argument-hint | <file, function, or module to test> |
| allowed-tools | ["Bash","Read","Edit","Write","Grep","Glob"] |
Write comprehensive, principled tests for the specified target: $ARGUMENTS
Before writing code, list the test cases you will write. Organize by category:
Happy path — Normal expected usage with valid inputs. Edge cases — Empty inputs, None/null, zero, single element, maximum/minimum values, unicode, whitespace. Error cases — Invalid inputs, missing required fields, type errors, permission failures. Boundary conditions — Off-by-one, empty collections, very large inputs, concurrent access. Integration points — If the code interacts with external systems, plan integration tests separately from unit tests.
Announce your test plan before writing any tests.
FIRST:
Test behavior, not implementation:
One concept per test:
test_process, test_function_workstest_returns_empty_list_when_no_items_match, test_raises_value_error_for_negative_amountArrange-Act-Assert:
# Arrange — set up inputs and dependencies
# Act — call the thing being tested (one action)
# Assert — verify the result
One act per test. If you need multiple acts, it's multiple tests.
| Mock | Don't Mock |
|---|---|
| External APIs, network calls | Your own internal functions |
| Databases (in unit tests) | Pure logic and computations |
| Filesystem, time, randomness | Deterministic code |
| Third-party services | Simple data transformations |
json.loads parses JSON).Before finishing, check each test against these criteria:
import pytest
class TestCalculateTax:
def test_calculates_tax_for_positive_amount(self):
result = calculate_tax(amount=100, rate=0.08)
assert result == 8.0
def test_returns_zero_for_zero_amount(self):
result = calculate_tax(amount=0, rate=0.08)
assert result == 0.0
def test_raises_for_negative_amount(self):
with pytest.raises(ValueError, match="must be positive"):
calculate_tax(amount=-100, rate=0.08)
@pytest.mark.parametrize("amount,rate,expected", [
(100, 0.10, 10.0),
(200, 0.05, 10.0),
(0, 0.10, 0.0),
])
def test_calculates_correctly_for_various_inputs(self, amount, rate, expected):
assert calculate_tax(amount, rate) == expected
pytest conventions:
conftest.py for shared fixtures. Don't duplicate fixture logic across files.@pytest.fixture for setup, not setUp/tearDown methods.@pytest.mark.parametrize for data-driven tests instead of copy-pasting.tmp_path fixture for filesystem tests instead of creating real temp directories.monkeypatch for patching instead of unittest.mock when possible.describe('calculateTax', () => {
it('calculates tax for positive amount', () => {
const result = calculateTax(100, 0.08);
expect(result).toBe(8);
});
it('returns zero for zero amount', () => {
expect(calculateTax(0, 0.08)).toBe(0);
});
it('throws for negative amount', () => {
expect(() => calculateTax(-100, 0.08)).toThrow('must be positive');
});
});
func TestCalculateTax(t *testing.T) {
tests := []struct {
name string
amount float64
rate float64
expected float64
}{
{"positive amount", 100, 0.08, 8.0},
{"zero amount", 0, 0.08, 0.0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := CalculateTax(tt.amount, tt.rate)
if got != tt.expected {
t.Errorf("CalculateTax(%v, %v) = %v, want %v", tt.amount, tt.rate, got, tt.expected)
}
})
}
}
| Anti-Pattern | Why It's Bad | Do This Instead |
|---|---|---|
| Testing private methods directly | Couples tests to implementation | Test through the public interface |
| Multiple asserts testing different concepts | Unclear what failed and why | One concept per test |
| Copy-paste test code everywhere | Hard to maintain, hides intent | Extract fixtures/helpers, but keep tests readable (DAMP > DRY) |
| Testing the mock instead of the code | Proves nothing about real behavior | Assert on outputs, not on mock call counts |
| Chasing 100% coverage blindly | Wastes time on trivial code | Focus coverage on critical and complex paths |
| Shared mutable state between tests | Order-dependent failures, flakiness | Fresh state per test via setup/fixtures |
| Testing framework behavior | Proves the framework works, not your code | Only test your logic |
| Sleeping in tests | Slow and flaky | Use proper async patterns or mocked time |
describe/it blocks (JS) or test classes/functions (Python) for clear organization.