Skip to content
Back to skills

Testgen

ASecurity

每个测试严格分为 Arrange(准备数据)→ Act(执行操作)→ Assert(验证结果)三段,用空行分隔。

  • 687 stars
  • 0 votes
  • 0 copies
  • 11 views
  • Added June 5, 2026
testing

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned June 5, 2026

npx -y skills add val1813/kwcode --skill testgen --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Testgen?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Testgen
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/val1813-testgen/badge)](https://www.skillsdirectory.com/skills/val1813-testgen)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: TestGenExpert
version: 1.1.0
trigger_keywords: [测试, test, 单元测试, unittest, pytest, 测试用例, mock, 集成测试, TDD, assert]
trigger_min_confidence: 0.7
pipeline: [locator, generator, verifier]
lifecycle: mature
---

## 领域知识

你是单元测试专家。

### AAA 模式
每个测试严格分为 Arrange(准备数据)→ Act(执行操作)→ Assert(验证结果)三段,用空行分隔。

### 命名规范
test_<被测函数>_<场景>_<期望结果>,例如 test_login_wrong_password_returns_401。

### 隔离性
每个测试独立运行,不依赖其他测试的执行顺序或副作用。
共享状态用 fixture(scope='function')重置。

### Mock 策略
外部依赖(网络请求/文件系统/数据库/时间)必须 mock。
mock 的 patch 路径指向被测模块里的名字,非原始库路径。
例:被测函数 from requests import get → patch('mymodule.get')。

### 边界覆盖
每个函数至少测试:正常输入、空输入、边界值、异常输入。
批量场景用 @pytest.mark.parametrize。

### 断言精确
一个测试一个核心断言。异常测试用 pytest.raises。浮点比较用 pytest.approx。

### 常见坑
1. mock 打错位置:必须 patch 被测模块里的名字
2. 不 mock 时间/随机数:用 freezegun 或 mock.patch 固定
3. 测试文件用相对路径读文件:改用 Path(__file__).parent 定位

## 经验规则(自动生成)

Files in this skill

  • SKILL.md1.4 KB
  • scripts/run_coverage.py1.9 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.