一键导入
testing-methodology
Testing methodology — test harness design, mock strategies, flakiness prevention, and structured test planning
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Testing methodology — test harness design, mock strategies, flakiness prevention, and structured test planning
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Visual-design discipline for forge frontends — brief the work before building (never invent an aesthetic without user input), declare the design system before coding, lean on the component library, use restrained color/type systems, never hand-draw complex SVGs, and verify visually before declaring done.
Write Next.js frontends — generated hooks, component library, Tailwind v4, visual verification, and Connect RPC clients.
Outbound boundary translators. One adapter per third-party system / queue / storage backend; narrow interface, vendor-neutral callers.
Write Connect RPC handlers — proto-driven codegen, the thin-translation handler pattern (validate, extract auth, convert proto↔internal, call service, wrap errors via `svcerr.Wrap`), middleware, and testing. Business logic lives in `internal/handlers/<svc>/contract.go`, never in handlers.
Forge project conventions and architecture — project structure, generated vs hand-written code, the generate pipeline, proto annotations, contracts, wiring, and naming.
Use-case orchestrators that compose two or more adapters/services. Deps are interfaces only — designed for unit tests with all-mock collaborators.
| name | testing-methodology |
| description | Testing methodology — test harness design, mock strategies, flakiness prevention, and structured test planning |
Before writing any tests, understand what exists:
npm test, make test, go test ./...)__tests__/, *_test.go, tests/)*.test.ts, *_test.py, Test*.java)Document findings - this information helps you and future agents write consistent tests.
The key to testing complex systems is good harnesses. A harness handles setup, teardown, and provides utilities so individual tests stay focused.
Keep REAL when:
MOCK when:
The boundary rule: Mock at system boundaries, keep internals real.
For API/backend testing:
TestHarness
├── Server (real, started once per suite)
├── Database (isolated per test, migrations run)
├── External Service Mocks (controllable)
└── Test Client (authenticated, with helpers)
For data layer testing:
TestHarness
├── Database Connection (transaction per test, rolled back)
├── Migration Runner (schema always current)
├── Fixture Loader (predictable test data)
└── Query Assertion Helpers
For message processing:
TestHarness
├── Queue (in-memory or real, isolated)
├── Worker Pool (controllable concurrency)
├── Event Collector (capture for assertions)
└── Completion Waiter (with timeout)
For integration points:
TestHarness
├── Mock Server (httptest, wiremock, etc.)
├── Request Recorder (verify calls made)
├── Response Programmer (control responses)
└── Failure Injector (test error handling)
Every test should have:
Names should describe the scenario and expected outcome:
test_create_user_with_valid_email_succeedsTestPaymentProcessor_RefundExceedingBalance_ReturnsErrorit('should reject duplicate usernames', ...)Timing issues:
time.Sleep(1s))// Bad
time.Sleep(2 * time.Second)
assert(result.IsComplete())
// Good
waitFor(func() bool { return result.IsComplete() }, timeout: 5s, poll: 100ms)
State isolation:
Live / heavy tests are opt-in:
RUN_LIVE_TESTS=1) and skip-with-a-reason when it's unset.Non-determinism:
Create tools that make testing easier. Write to .reliant/tools/ or the project's scripts directory.
Run specific test suites:
#!/bin/bash
# .reliant/tools/test-unit.sh
go test -short ./...
Run with coverage:
#!/bin/bash
# .reliant/tools/test-coverage.sh
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
echo "Coverage report: coverage.html"
Seed test database:
#!/bin/bash
# .reliant/tools/seed-test-db.sh
DB_PATH="${TEST_DB:-./test.db}"
sqlite3 "$DB_PATH" < ./testdata/seed.sql
echo "Test database seeded at $DB_PATH"
Run flaky test detector:
#!/bin/bash
# .reliant/tools/flaky-detector.sh
TEST_NAME="$1"
RUNS="${2:-10}"
for i in $(seq 1 $RUNS); do
if ! go test -run "$TEST_NAME" ./...; then
echo "FLAKY: Failed on run $i"
exit 1
fi
done
echo "STABLE: Passed $RUNS consecutive runs"
When reviewing code or planning tests, provide a structured test plan:
| Function/Method | Test Cases | Priority |
|---|---|---|
validateEmail | valid format, invalid format, empty, unicode | High |
calculateTotal | normal, with discount, zero items, overflow | High |
| Scenario | Components | Mocking Strategy |
|---|---|---|
| User registration flow | API + DB + Email | Mock email service |
| Payment processing | API + DB + Stripe | Mock Stripe API |
| User Flow | Steps | Assertions |
|---|---|---|
| Complete checkout | Login -> Add item -> Pay -> Confirm | Order created, email sent |
| Component | Decision | Rationale |
|---|---|---|
| Database | Real (postgres) | Need to test actual queries |
| Redis | Mock | Not testing caching logic |
| Stripe API | Mock | External, non-deterministic |