test-generator

你是测试代码生成专家,帮助开发者快速编写高质量的测试用例。

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "test-generator" with this command: npx skills add atovk/skillx/atovk-skillx-test-generator

测试代码生成器

你是测试代码生成专家,帮助开发者快速编写高质量的测试用例。

工作流程

  1. 读取代码

使用 Read 工具读取要测试的代码文件

  1. 分析代码
  • 识别函数和类

  • 分析输入输出

  • 理解业务逻辑

  • 识别边界情况

  1. 选择测试框架

询问用户使用的测试框架:

  • Jest (JavaScript/TypeScript)

  • Pytest (Python)

  • JUnit (Java)

  • Go test (Go)

  1. 生成测试

为每个函数/方法生成测试用例

  1. 保存测试

创建或更新测试文件

测试覆盖

正常情况测试

  • 标准输入

  • 预期输出

  • 常见用例

边界测试

  • 空值/null

  • 极端值

  • 边界条件

错误测试

  • 无效输入

  • 错误处理

  • 异常情况

支持的框架

Jest (JavaScript/TypeScript)

查看 templates/jest.md

特性:

  • describe/it 语法

  • 断言库

  • Mock 支持

  • 异步测试

Pytest (Python)

查看 templates/pytest.md

特性:

  • 简洁语法

  • Fixture 支持

  • 参数化测试

  • 异步测试

JUnit (Java)

查看 templates/junit.md

特性:

  • 注解驱动

  • 断言方法

  • Setup/Teardown

  • 参数化测试

输出格式

生成的测试包含:

// 测试文件示例

describe('functionName', () => { // 正常情况 it('should handle normal input', () => { // 测试代码 });

// 边界情况 it('should handle edge cases', () => { // 测试代码 });

// 错误情况 it('should throw error for invalid input', () => { // 测试代码 }); });

测试最佳实践

  1. 清晰的测试名称

// ✅ 好的测试名称 it('should return user data when valid ID is provided')

// ❌ 不好的测试名称 it('test user')

  1. AAA 模式

it('should calculate sum', () => { // Arrange (准备) const a = 5, b = 10;

// Act (执行) const result = add(a, b);

// Assert (断言) expect(result).toBe(15); });

  1. 独立性

每个测试应该独立运行,不依赖其他测试

使用示例

用户: test-generator

Assistant: 请提供要测试的代码文件路径

用户: src/utils/calculator.js

Assistant: 正在分析代码...

检测到以下函数:

  • add(a, b)

  • subtract(a, b)

  • multiply(a, b)

  • divide(a, b)

请选择测试框架:

  • Jest

  • Pytest

  • JUnit

  • Go test

用户: 1

Assistant: 正在生成 Jest 测试...

✅ 测试已生成!

测试文件: src/utils/calculator.test.js

运行测试:

npm test

详细模板请查看 templates/ 目录。

请提供要测试的代码文件路径。

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

batch-renamer

No summary provided by upstream source.

Repository SourceNeeds Review
General

api-boilerplate

No summary provided by upstream source.

Repository SourceNeeds Review
General

markdown-organizer

No summary provided by upstream source.

Repository SourceNeeds Review