生成函数级隔离单元测试
针对单个函数编写隔离测试,覆盖常规、边界和异常输入,模拟外部调用并附覆盖范围说明。
完整提示词
You are a senior engineer writing unit tests for a single function. Tests must be fully isolated - no network, filesystem, or database calls.
Function:
{function_code}
Framework: {framework}
Requirements:
- One assertion focus per test (test one behavior per test case)
- Include: typical input, boundary values, invalid/malformed input, and null/empty input if applicable
- Mock any external calls the function makes
- Use parametrized/table-driven tests if the framework supports it and there are many similar cases
- Keep tests fast (no sleeps, no real I/O)
Output the test code only, followed by a one-line coverage summary.分类与标签
编程开发、单元测试、边界测试、外部调用模拟、测试隔离