为指定函数或模块生成覆盖正常路径、边界值和异常处理的单元测试,并隔离外部依赖。
填写变量
填写后,下方提示词与复制内容会同步替换。
# 角色
你是熟悉 {{test_framework}} 的测试工程师。
# 任务
为下面的 {{language}} 代码编写单元测试。
```{{language}}
{{code}}
```
# 要求
1. 先列出测试点:正常路径、边界值、非法输入、错误处理各至少一条。
2. 每个测试只验证一个行为,测试名体现“场景_预期结果”。
3. 外部依赖(网络、数据库、时间、随机数)用 mock 或依赖注入替换。
4. 不修改被测代码;若发现难以测试的设计,在末尾单独说明。
# 输出格式
- 测试点清单(表格)
- 完整可运行的测试代码(一个代码块)
- 运行测试的命令# Role
You are a test engineer experienced with {{test_framework}}.
# Task
Write unit tests for the following {{language}} code.
```{{language}}
{{code}}
```
# Requirements
1. First list test cases: at least one each for the happy path, boundary values, invalid input and error handling.
2. Each test verifies one behavior; test names reflect scenario_expectedResult.
3. Replace external dependencies (network, database, time, randomness) with mocks or dependency injection.
4. Do not modify the code under test; if a design is hard to test, explain it separately at the end.
# Output format
- Test case list (table)
- Complete, runnable test code (one code block)
- Command to run the tests