v0.1.0 现已发布 v0.1.0 Available Now

从需求文档到
高质量测试用例
Spec-Driven
Test Generation

让 AI 帮你把 PRD 变成高质量测试用例。按模块拆分,全程可追溯,专为高效交付的团队设计。

Transform PRDs into structured test cases with AI. Modular, traceable, and built for teams that ship.

terminal -- zsh
$ testspec analyze prd.md -o coupon-system
✓ 分析完成 -- 识别出 6 个模块
✓ 默认功能设置为: coupon-system
✓ Analysis complete -- 6 modules identified
✓ Default feature set to: coupon-system
$ testspec list
┌──────┬─────────────────────┬────────┬──────────┐
│ 001 │ coupon-type-manager │ -- │ 待处理Pending
│ 002 │ coupon-claim │ -- │ 待处理Pending
│ 003 │ coupon-use │ -- │ 待处理Pending
└──────┴─────────────────────┴────────┴──────────┘
$ testspec generate --module 002-coupon-claim

大小项目,都能搞定 Built for Scale

不管是一个小功能还是一整套复杂系统,testspec 都能融入你的工作方式。

From small features to complex systems. testspec adapts to your workflow.

01

模块化设计Modular by Design

PRD 很大?没关系。可以逐个模块处理,也可以批量跑完,每个模块的进度都清清楚楚。

Large PRD? No problem. Process modules individually or in batches. Each module gets its own tracking and status.

02

记住上下文Smart Defaults

只要跑过一次 testspec analyze,后面的命令就不用再带 -o 参数了——工具会自动记住你在做哪个功能。

Run testspec analyze once, then omit the -o flag. The tool remembers your context and picks up where you left off.

03

编辑器里直接用IDE Integration

在 Cursor 里用斜杠命令,在 Qoder 里用结构化提示词,不用离开编辑器就能跑完整个流程。

Native slash commands for Cursor. Structured prompts for Qoder. Works where you work.

04

团队标准,一次定义Constitution-Driven

把团队的测试规范写进 constitution.md,之后不管谁来生成用例,格式、覆盖率、质量标准都一样。

Define your team's testing standards once. AI follows your rules for format, coverage, and quality on every generation.

05

一目了然的进度Progress Tracking

一条命令看到所有模块的处理进度,哪些做完了、哪些还没开始,不用翻文件去找。

Visual module list shows exactly what's done and what's pending. No more guessing about test coverage.

06

Excel 导出Excel Export

一条命令导出 Excel,自带优先级颜色标注和筛选功能,拿到手就能用,直接导入测试管理工具。

One command exports all test cases to formatted Excel. Priority color-coding, auto-filter, ready for your test management tool.

分析 → 策略 → 生成 → 审查 ANALYZE → STRATEGY → GENERATE → REVIEW

四步走完,从需求到测试用例,每一步都可审查、可回溯。

A disciplined pipeline that turns requirements into verified test coverage.

1

ANALYZE

testspec analyze -o <name>

读取 PRD 文档,自动拆解出可测试的功能模块,每个模块分配编号和英文名。

Parse the PRD and decompose into testable modules. Each module gets a numbered ID and English identifier.

tests/coupon-system/
└── analysis.md           # 识别出 6 个模块# 6 modules identified
2

STRATEGY

testspec strategy [--module <id>]

为每个模块规划测试维度、评估优先级、预估要写多少条用例。

Define test dimensions, priorities, and estimated case counts for each module.

模块: 002-coupon-claim
优先级: P0 | 预估用例: 12
维度: 功能、边界、异常、性能
Module: 002-coupon-claim
Priority: P0 | Est. Cases: 12
Dimensions: Functional, Boundary, Exception, Performance
3

GENERATE

testspec generate [--module <id>]

按策略生成结构化的测试用例,统一编号格式 TC-{模块}-{序号}。

Produce structured test cases with numbered IDs. Format: TC-{module}-{sequence}.

## 002-coupon-claim
### TC-002-001: 有效优惠券领取Valid coupon claim
优先级: P0 | 类型: 功能Priority: P0 | Type: Functional
4

REVIEW

testspec review [--module <id>]

对照 constitution 检查覆盖率,找出遗漏的场景和质量问题,给出具体补充建议。

Coverage audit against the constitution. Identify gaps, quality issues, and receive specific recommendations.

覆盖率: 94% | 缺失: 2 个边界场景
质量: ✓ 所有步骤可执行
操作: 添加 TC-002-013, TC-002-014
Coverage: 94% | Missing: 2 boundary cases
Quality: ✓ All steps executable
Action: Add TC-002-013, TC-002-014

5 分钟上手 Up and Running in 5 Minutes

从装好工具到拿到第一份 Excel,跟着下面几步走就行。

From install to your first test case Excel, just follow these steps.

1 安装 testspec Install testspec

拉取代码,用开发模式装好,之后在任意位置都能用 testspec 命令。

Clone the repo and install in editable mode. The testspec command becomes globally available.

bash
git clone https://github.com/Dev-Trainee/testspec.git # 或者从 Gitee 拉取: git clone https://gitee.com/Dev-Trainee/testspec.git cd testspec && pip install -e .
2 初始化你的项目 Initialize Your Project

进入你的项目目录,运行 init 命令。会自动生成 .testspec/ 配置目录和 IDE 集成文件。

Run init in your project root to generate the .testspec/ directory (including constitution.md and config.yaml) plus IDE integration files.

bash
cd your-project testspec init # 生成的目录结构: # .testspec/ # ├── constitution.md (团队测试规范) # ├── config.yaml (项目配置) # └── memory/ (可放入历史用例作参考)
3 运行完整流程 Run the Full Pipeline

准备好 PRD 文档,按顺序跑四个阶段就行。每一步都会输出 Markdown 中间文件,你可以看完再决定要不要继续。

With your PRD ready, run through the four stages. Each stage produces intermediate Markdown files for human review before proceeding.

bash
# 第 1 步:分析 PRD,拆出功能模块 testspec analyze docs/prd-coupon.md -o coupon-system # 查看模块清单 testspec list # 第 2 步:制定测试策略(全量或单个模块) testspec strategy --all-modules # 或: testspec strategy --module 002-coupon-claim # 第 3 步:生成测试用例 testspec generate --all-modules # 第 4 步:检查覆盖率 testspec review --all-modules
4 导出 Excel Export to Excel

最后一步,一条命令就能把所有用例导出成带格式的 Excel,交给团队直接用。

One command exports all cases to a formatted Excel with priority color-coding and auto-filters, ready for your team.

bash
testspec export # 输出: tests/coupon-system/cases.xlsx # ✓ 已导出 25 条测试用例

看看产出物长什么样 See What You Get

拿一个优惠券系统的 PRD 当例子,看看每个阶段跑出来是什么样的。

Using a coupon system PRD as an example, see the actual output from each stage.

tests/coupon-system/analysis.md
# 优惠券系统 - 模块分析Coupon System - Module Analysis
来源: docs/prd-coupon.mdSource: docs/prd-coupon.md

## 模块列表Module List

### 001-coupon-type-manager
描述: 优惠券类型管理,包括创建、编辑、删除、上下架Description: Coupon type management: create, edit, delete, enable/disable
复杂度:Complexity: 中等Medium

### 002-coupon-claim
描述: 用户领取优惠券,包括领取规则、上限、时间窗口Description: User coupon claiming with rules, limits, and time windows
复杂度:Complexity: High

### 003-coupon-use
描述: 优惠券使用与核销,包括满减、折扣、叠加规则Description: Coupon redemption: threshold, discount, stacking rules
复杂度:Complexity: High

### 004-coupon-expire
描述: 优惠券过期处理与自动回收机制Description: Coupon expiration handling and auto-reclaim
复杂度:Complexity: Low

### 005-coupon-statistics
描述: 优惠券发放与使用的数据统计和报表Description: Coupon distribution and usage statistics
复杂度:Complexity: 中等Medium

### 006-coupon-push
描述: 优惠券推送和提醒通知Description: Coupon push notifications and reminders
复杂度:Complexity: Low
tests/coupon-system/strategy.md
# 优惠券系统 - 测试策略Coupon System - Test Strategy

## 002-coupon-claim

优先级:Priority: P0
预估用例数:Est. Cases: 12

测试维度:Test Dimensions:
功能测试 - 正常领取流程、不同优惠券类型领取Functional - Normal claim flow, different coupon type claims
边界测试 - 领取上限、时间窗口边界、库存为 0Boundary - Claim limits, time window edges, zero inventory
异常测试 - 重复领取、已过期活动、无权限用户Exception - Duplicate claims, expired campaigns, unauthorized users
并发测试 - 高并发领取、库存扣减竞态Concurrency - High-concurrency claims, inventory race conditions

## 003-coupon-use

优先级:Priority: P0
预估用例数:Est. Cases: 15

测试维度:Test Dimensions:
功能测试 - 满减计算、折扣计算、多商品场景Functional - Threshold calculation, discount logic, multi-item scenarios
边界测试 - 刚好满足门槛、小数精度、最大优惠金额Boundary - Exact threshold, decimal precision, max discount amount
异常测试 - 过期券使用、已核销券、不满足条件Exception - Expired coupons, already-used coupons, unmet conditions
tests/coupon-system/cases.md
# 优惠券系统 - 测试用例Coupon System - Test Cases

## 002-coupon-claim

### TC-002-001: 有效优惠券正常领取Valid coupon normal claim
优先级:Priority: P0 | 类型:Type: 功能Functional
前置条件:Precondition: 用户已登录,优惠券活动进行中,库存 > 0User logged in, campaign active, inventory > 0
步骤:Steps:
  1. 进入优惠券领取页面Navigate to coupon claim page
  2. 点击"立即领取"按钮Click "Claim Now" button
  3. 确认领取弹窗Confirm claim dialog
期望结果:Expected: 领取成功,"我的优惠券"列表新增一条记录,库存 -1Claim succeeds, new entry in "My Coupons", inventory -1

### TC-002-002: 达到领取上限后再次领取Claim after reaching limit
优先级:Priority: P0 | 类型:Type: 边界Boundary
前置条件:Precondition: 用户已领取该券 N 张(N = 领取上限)User has claimed N coupons (N = claim limit)
步骤:Steps:
  1. 尝试再次领取同一优惠券Attempt to claim the same coupon again
期望结果:Expected: 提示"已达领取上限",领取按钮置灰Show "Claim limit reached", button disabled

### TC-002-003: 库存为 0 时领取Claim with zero inventory
优先级:Priority: P0 | 类型:Type: 边界Boundary
...
tests/coupon-system/cases.xlsx
用例编号Case ID 模块Module 用例标题Title 优先级Priority 类型Type 前置条件Precondition 测试步骤Steps 期望结果Expected
TC-002-001 002-coupon-claim 有效优惠券正常领取Valid coupon normal claim P0 功能Functional 用户已登录,活动进行中User logged in, campaign active 1. 进入领取页 2. 点击领取1. Go to claim page 2. Click claim 领取成功,库存-1Claim succeeds, inventory-1
TC-002-002 002-coupon-claim 达到领取上限Claim limit reached P0 边界Boundary 已领取 N 张 (N=上限)Claimed N coupons (N=limit) 1. 再次点击领取1. Click claim again 提示"已达上限"Show "limit reached"
TC-003-001 003-coupon-use 满减券正常使用Threshold coupon normal use P0 功能Functional 持有满100减20券,订单>100Has $100-$20 coupon, order>$100 1. 下单 2. 选择优惠券1. Place order 2. Select coupon 订单金额减20Order total reduced by $20
TC-003-002 003-coupon-use 订单未满足满减门槛Order below threshold P1 边界Boundary 持有满100减20券,订单=99Has $100-$20 coupon, order=$99 1. 尝试使用优惠券1. Try to apply coupon 提示"未满足使用条件"Show "conditions not met"
TC-004-001 004-coupon-expire 到期自动失效Auto-expire on due date P1 功能Functional 持有即将到期的优惠券Has coupon about to expire 1. 等待过期 2. 查看状态1. Wait for expiry 2. Check status 状态变为"已过期"Status changes to "Expired"
↓ 下载完整示例项目 ↓ Download Full Example Project

你的规则,AI 遵守 Your Rules, AI Follows

在 constitution.md 里写好你们团队的测试规范,AI 每次生成都会照着做。

Define your team's testing standards in constitution.md. AI enforces them on every generation.

.testspec/constitution.md
# 测试规范Test Constitution

## 格式规范Format Rules
- 用例编号格式: TC-{模块编号}-{三位序号} - Case ID format: TC-{module}-{3-digit seq}
- 每条用例必须包含: 前置条件、步骤、期望结果 - Each case must include: precondition, steps, expected result
- 步骤描述使用"动词 + 对象"句式 - Steps use "verb + object" pattern

## 覆盖率要求Coverage Requirements
- P0 功能: 正向 + 至少 2 个反向场景 - P0 features: positive + at least 2 negative scenarios
- 涉及金额的模块必须包含精度边界测试 - Monetary modules must include precision boundary tests
- 并发场景: 所有涉及库存的模块 - Concurrency: all inventory-related modules

## 质量标准Quality Standards
- 期望结果必须可验证,避免"正确显示"等模糊描述 - Expected results must be verifiable, avoid vague terms like "displays correctly"
- 测试数据使用具体值,不使用"某个值"等占位符 - Use concrete test data, never placeholders like "some value"
格式一致性 Format Consistency

写清楚编号怎么排、哪些字段必填、文案怎么写。不管谁来跑,输出都是一样的格式。

Define case ID rules, required fields, and writing style. Consistent output regardless of who runs testspec.

覆盖率保障 Coverage Guarantee

设好覆盖率底线。正向、反向、边界、异常都得有,review 阶段还会再查一遍有没有漏的。

Set minimum coverage requirements. AI must cover positive, negative, boundary, and exception dimensions. Review stage auto-checks for gaps.

质量门控 Quality Gate

不允许写"正确显示"这种模糊描述,每条用例都要能直接拿去执行,减少返工。

No vague descriptions or placeholder data. Every case must be "directly executable", reducing manual rework.

团队沉淀 Team Knowledge

这个文件跟着代码一起做版本管理。团队的测试经验不断沉淀,新人来了也能输出高质量用例。

Constitution lives in version control. Team testing knowledge accumulates over time. New members produce high-quality cases from day one.

在你的编辑器里直接用 Use It Right in Your IDE

Cursor 用斜杠命令、Qoder 用结构化提示词,不需要切到终端。

Native slash commands for Cursor and structured prompts for Qoder. No context switching.

C
Cursor
斜杠命令集成
Slash Command Integration
1 运行 testspec init,会自动生成 .cursor/commands/ 目录 Run testspec init to auto-generate .cursor/commands/ directory
2 在 Agent 输入框里输入 /,就能看到 testspec 的命令列表 Type / in Agent input to see testspec commands
3 选一个命令,比如 /testspec.analyze,按提示填入参数即可 Select a command like /testspec.analyze and follow the prompts
可用命令Available Commands
/testspec.analyze # 分析 PRD# Analyze PRD /testspec.strategy # 制定策略# Define strategy /testspec.generate # 生成用例# Generate cases /testspec.review # 审查覆盖率# Review coverage
Q
Qoder
结构化提示词集成
Structured Prompt Integration
1 运行 testspec init,会生成 AGENTS.md 指导文件 Run testspec init to generate AGENTS.md guide file
2 在 Qoder Agent 对话里引用 AGENTS.md,就可以用工作流命令了 In Qoder Agent chat, reference AGENTS.md to use workflow commands
3 Agent 会自动读取 constitution 和 config,按 testspec 流程一步步执行 Agent auto-reads constitution and config, executing the testspec pipeline
对话示例Chat Example
# 在 Qoder Agent 里直接说:# Type directly in Qoder Agent:
"请分析 docs/prd-coupon.md,"Please analyze docs/prd-coupon.md,
输出到 coupon-system" output to coupon-system"

# Agent 会自动按 testspec 流程执行# Agent auto-executes testspec pipeline

常见问题 Frequently Asked Questions

直接让 AI 写用例不就行了,为什么还要用 testspec? How is testspec different from just asking AI to generate test cases?
直接让 AI 写,最大的问题是没有约束——格式五花八门、想到哪写到哪、覆盖率全凭运气。testspec 做的事情是给 AI 加上"规矩":通过 constitution 约束标准,四个阶段逐步推进,每一步都能人工审查。PRD 再大也不怕,按模块拆开一个个来,而不是一股脑扔给 AI 然后祈祷。 Directly asking AI lacks structural constraints, leading to inconsistent formats, coverage gaps, and variable quality. testspec uses a constitution file to define standards, a 4-stage pipeline for quality gates at each step, and modular design for handling large PRDs. Each stage produces intermediate files for human review rather than a one-shot "black box" output.
需要配置 API Key 吗?支持哪些 LLM? Do I need an API key? Which LLMs are supported?
有两种用法。如果你想在终端里直接跑,需要配一个 OpenAI 兼容的 API Key,GPT-4、Claude、DeepSeek 都行。如果你在 Cursor 或 Qoder 里用,完全不需要 Key——工具会生成结构化的提示词文件,交给编辑器内置的 AI 来执行。 testspec supports two modes: API mode requires an OpenAI-compatible API key (supports GPT-4, Claude, DeepSeek, etc.) for direct LLM calls; Prompt mode requires no API key -- it generates structured prompt files that are executed by Cursor's or Qoder's built-in AI.
老项目能用吗? Can I use this for existing projects or only new ones?
当然可以。进到项目根目录跑一下 testspec init 就行。如果之前已经有一些测试用例了,可以丢到 .testspec/memory/ 目录里,AI 生成新用例时会参考这些历史数据,避免重复。 Works perfectly with existing projects. Just run testspec init in your project root. You can place existing test cases in the .testspec/memory/ directory as reference. AI will consider this historical data when generating new cases, avoiding duplicates and maintaining consistency.
生成出来的用例靠谱吗?还需要人看吗? How is the quality of generated test cases? Do I need manual review?
四阶段设计本身就是在把关质量:先理解需求、再定策略、然后生成、最后审查。不过我们建议每个阶段都快速扫一眼产出结果,尤其是 analyze(AI 有没有理解对需求)和 review(有没有漏掉的场景)这两步。毕竟 AI 是工具,最终把关的还是人。 testspec's 4-stage design has built-in quality assurance: analyze ensures correct requirement understanding, strategy ensures comprehensive test dimensions, generate outputs according to constitution standards, and review performs coverage audits against the constitution. We recommend quick human checks at each stage, especially analyze and review, to ensure AI understanding matches team expectations.
支持中文 PRD 吗? Does it support non-English PRDs?
完全没问题。PRD 是中文就生成中文用例,是英文就生成英文用例。模块编号统一用英文命名(比如 002-coupon-claim),但用例的标题、步骤、预期结果都会跟着 PRD 的语言走。你也可以在 constitution.md 里指定偏好语言。 Fully supported. testspec handles PRDs in any language. Module IDs use English identifiers (e.g., 002-coupon-claim), but case titles, steps, and expected results match the PRD's language. You can specify language preferences in constitution.md.
多人协作怎么搞? How does team collaboration work? Can multiple people use it simultaneously?
所有配置文件和产出都是纯文本,天然适合 Git 管理。团队里每个人可以负责不同的模块(用 --module 参数),各做各的,最后合到同一个 tests/ 目录就行。constitution.md 是共享的,保证大家的输出标准一致。 All testspec config files (constitution.md, config.yaml) and outputs (analysis.md, cases.md, etc.) are plain text files managed through Git. Team members can work on different modules (via --module flag) and merge into the same tests/ directory.