Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add rules/xyzbit/ai-coding/d-test-unit-testgit clone --depth 1 https://github.com/xyzbit/AI-CodingWhat it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00006 | $0.00871 |
| Opus 5 | $0.00003 | $0.00436 |
| Sonnet 5 | $0.00001 | $0.00174 |
| Haiku 4.5 | $0.00001 | $0.00087 |
Grade A, and why
d-test-unit-test scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
What it actually says
Golang 单元测试规范
命名规范
- 测试文件命名:
xxx_test.go - 测试函数命名:
Test${被测试函数名} - 基准测试函数:
Benchmark${被测试函数名} - 示例函数:
Example${被测试函数名}
测试用例组织
- 使用
t.Run()进行子测试分组 - 每个测试场景应该有清晰的描述
- 使用表驱动测试方式组织多个测试用例
- 测试覆盖率要求 > 60%
测试代码结构
func TestXxx(t *testing.T) {
// 1. 准备测试数据
type args struct {
// 输入参数
}
tests := []struct {
name string // 测试用例名称
args args // 输入参数
want interface{} // 期望输出
wantErr bool // 是否期望错误
}{
// 测试用例列表
}
// 2. 执行测试
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// 3. 准备测试环境(如果需要)
// 4. 执行被测试函数
// 5. 验证结果
// 6. 清理测试环境(如果需要)
})
}
}
测试原则
- 单一职责:每个测试用例只测试一个功能点
- 独立性:测试用例之间相互独立,不应该有依赖关系
- 可重复:测试结果应该是稳定的,多次运行结果一致
- 简单明了:测试代码应该简单易懂,避免复杂的逻辑
Mock 使用规范
- 优先使用接口进行依赖注入,便于 mock
- 推荐使用
go-mock、testify/mock等工具 - Mock 对象应该在测试函数开始时创建,结束时销毁
断言规范
- 推荐使用
testify/assert包进行断言 - 使用恰当的断言函数,如:
assert.Equal(t, expected, actual)assert.NoError(t, err)assert.True(t, condition)
最佳实践
- 测试文件与源文件放在同一目录下
- 优先测试接口而不是实现细节
- 避免测试私有方法,通过公共接口测试
- 合理使用测试辅助函数减少重复代码
- 及时清理测试产生的临时资源
- 编写测试时考虑边界条件和异常场景
示例
func TestCalculator_Add(t *testing.T) {
type args struct {
a, b int
}
tests := []struct {
name string
args args
want int
wantErr bool
}{
{
name: "正常相加",
args: args{a: 1, b: 2},
want: 3,
},
{
name: "负数相加",
args: args{a: -1, b: 1},
want: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := NewCalculator()
got := c.Add(tt.args.a, tt.args.b)
assert.Equal(t, tt.want, got)
})
}
}
运行测试
- 运行所有测试:
go test ./... - 运行指定包测试:
go test ./pkg/... - 运行指定函数:
go test -run TestXxx - 显示详细日志:
go test -v
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2d ago First seen · 115 lines · 6 tokens per session scan A 9a8c0e3d52bb
d-test-unit-test is a cursor rule published in the GitHub repository xyzbit/AI-Coding (21 stars, last pushed 10mo ago), licensed Apache-2.0. It adds 6 tokens to every session and 871 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other cursor rules, from other repositories
angular-20
This rule provides comprehensive best practices and coding standards for Angular development, focusing on modern TypeScript, standalone components, signals, and performance optimizations.
dev-standard
Apache Superset development standards and guidelines for Cursor IDE.
typescript
Changes to these high-fan-out internals can affect every message, delta, element, or rerun. Keep work in them minimal, and benchmark changes with representative stress-test apps.
coolify-ai-docs
Master reference to all Coolify AI documentation in .ai/ directory.
python_lib
Tips and guidelines specific to the development of the Streamlit Python library, not applicable to scripts and e2e tests.
specs
This directory contains product and tech specs for Streamlit features.