testing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTesting
测试
Test-driven by default. Prove the problem before solving it.
默认采用测试驱动模式,解决问题前先验证问题真实存在。
Core Workflow: Bug First
核心工作流:Bug 优先
- Reproduce — Run the failing scenario and observe the actual behavior
- Write a failing test — Minimal reproduction as a test case
- Commit the failing test — Use with message like
Skill(commit)test: reproduce #issue-description - Fix the code — Only now attempt the fix
- Verify — Run and confirm the test passes
pnpm test - Commit the fix — Separate commit from the test
This applies to all bug fixes. The failing test proves the bug exists and prevents regressions.
- 复现 — 运行失败场景,观察实际行为
- 编写失败测试 — 以最小化复现代码编写测试用例
- 提交失败测试 — 使用 ,提交信息格式类似
Skill(commit)test: reproduce #issue-description - 修复代码 — 仅在这一步尝试修复
- 验证 — 运行 确认测试通过
pnpm test - 提交修复 — 修复代码单独提交,与测试提交分开
该流程适用于所有 Bug 修复。失败的测试既能证明 Bug 真实存在,也能防止后续出现回归问题。
Fixture Tests
Fixture 测试
Noodle uses directory-based fixtures in . Read references/fixtures.md for full format, helper API, and code patterns.
testdata/Noodle 在 目录下使用基于目录的 Fixture。完整格式、辅助 API 及代码模式请查阅 references/fixtures.md。
testdata/Creating a New Fixture
创建新 Fixture
sh
./scripts/scaffold-fixture.sh <package-dir> <fixture-name> [state-count]Fill in the generated / and , then:
input.jsoninput.ndjsonexpected.mdsh
pnpm fixtures:hash:syncsh
./scripts/scaffold-fixture.sh <package-dir> <fixture-name> [state-count]填写生成的 / 和 ,然后执行:
input.jsoninput.ndjsonexpected.mdsh
pnpm fixtures:hash:syncBug Fixtures
Bug Fixture
See references/fixtures.md for full bug fixture format (frontmatter fields, expected error sections, and the fix workflow).
完整的 Bug Fixture 格式(frontmatter 字段、预期错误部分、修复工作流)请查阅 references/fixtures.md。
Key Commands
常用命令
| Command | Purpose |
|---|---|
| Run all tests |
| Skip integration tests |
| Full local CI (test + vet + lint + fixtures) |
| List fixtures marked as known bugs |
| Verify loop fixtures match expected |
| Regenerate loop fixture expected output |
| Verify fixture input hashes |
| Update fixture input hashes |
| Run |
| Architecture lint (file sizes, legacy patterns) |
| 命令 | 用途 |
|---|---|
| 运行所有测试 |
| 跳过集成测试 |
| 完整本地 CI 检查(测试 + vet + lint + Fixture 校验) |
| 列出标记为已知 Bug 的 Fixture |
| 验证循环 Fixture 与预期结果一致 |
| 重新生成循环 Fixture 的预期输出 |
| 验证 Fixture 输入哈希 |
| 更新 Fixture 输入哈希 |
| 运行 |
| 架构 Lint 检查(文件大小、遗留模式) |
Running Specific Tests
运行指定测试
sh
undefinedsh
undefinedSingle package
Single package
go test ./loop
go test ./loop
Single test
Single test
go test ./loop -run TestLoopDirectoryFixtures
go test ./loop -run TestLoopDirectoryFixtures
Bypass cache
Bypass cache
go test -count=1 ./parse
go test -count=1 ./parse
With race detector
With race detector
go test -race ./...
go test -race ./...
Verbose
Verbose
go test -v ./tui
undefinedgo test -v ./tui
undefinedIntegration Tests
集成测试
Long-running or external-dependency tests use :
testing.Short()go
if testing.Short() {
t.Skip("skipping integration test in short mode")
}pnpm test:shortpnpm test运行时间长或依赖外部资源的测试使用 :
testing.Short()go
if testing.Short() {
t.Skip("skipping integration test in short mode")
}pnpm test:shortpnpm test