用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/li-kai/bastion --skill write-tests命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | write-tests |
| description | Testing best practices, TDD workflow, and test structure. Use when writing or reviewing tests. |
Describe behavior, not implementation. A reader should understand what's tested without reading the body.
// Bad
test_parser()
handles_edge_case()
// Good
rejects_negative_amounts()
parse_returns_error_when_input_is_empty()
Prefer parameterized tests over duplication. Name cases for clarity:
Rust (rstest):
#[rstest]
#[case::empty("", 0)]
#[case::unicode("日本語", 3)]
fn char_count(#[case] input: &str, #[case] expected: usize) {
assert_eq!(input.chars().count(), expected);
}
TypeScript (Vitest):
test.each([
{ name: "empty", input: "", expected: 0 },
{ name: "unicode", input: "日本語", expected: 3 },
])("char_count($name)", ({ input, expected }) => {
expect(charCount(input)).toBe(expected)
})
Keep tests flat. Avoid nested describe/context blocks.
One behavior per test. A failing test should pinpoint the bug. If a test asserts multiple unrelated behaviors, split it.
Minimal setup. Only set up what the test needs. Long setup suggests the code under test has too many dependencies.
Test boundaries, not internals. Test public APIs.
Test behavior, not implementation. Tests should survive refactors. If changing internals (without changing behavior) breaks tests, they're too coupled.
Descriptive failures. When a test fails, the output should explain what went wrong:
// Bad: "assertion failed: result.is_ok()"
assert!(result.is_ok());
// Good: "parse failed: InvalidToken at line 3"
let ast = parse(input).expect("parse failed");
// Bad: shows generic matcher failure
expect(result.ok).toBe(true)
// Good: shows the actual error
expect(result.error).toBeUndefined()
Use expect tests for outputs that are:
Avoid expect tests when:
Rust (expect_test):
use expect_test::expect;
#[test]
fn formats_error() {
let err = parse("invalid {").unwrap_err();
expect![[r#"
ParseError: unexpected end of input
at line 1, column 9
"#]].assert_eq(&err.to_string());
}
Update snapshots: UPDATE_EXPECT=1 just test
TypeScript (Vitest):
import { expect, test } from "vitest"
test("formats error", () => {
const err = parse("invalid {")
expect(err.message).toMatchInlineSnapshot(`
"ParseError: unexpected end of input
at line 1, column 9"
`)
})
Update snapshots: pnpm test -u
Review discipline: Treat snapshot updates like code changes. Diff them carefully—automated updates can silently accept bugs.