test-gen

test-gen is a skill for Claude Code, Codex from guyulong/cn-agent-skills. It costs 8 tokens per session (862 once invoked), scanned A, original, MIT.

A tool for generating unit tests, which check small pieces of a program separately, for Python and JavaScript code.

In plain words
What is it for?
Use it to create Python tests with pytest or JavaScript tests with Jest for functions and classes.
Why use it?
It reduces the effort of writing tests for normal cases, unusual inputs, and expected errors.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to create Python tests with pytest or JavaScript tests with Jest for functions and classes.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/guyulong/cn-agent-skills/test-gen
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add guyulong/cn-agent-skills --skill test-gen
Clone the repo
git clone --depth 1 https://github.com/guyulong/cn-agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for test-gen

README.md
[![agentmods](https://agentmods.dev/badge/skills/guyulong/cn-agent-skills/test-gen/github.svg)](https://agentmods.dev/skills/guyulong/cn-agent-skills/test-gen)
Your own site
<a href="https://agentmods.dev/skills/guyulong/cn-agent-skills/test-gen"><img src="https://agentmods.dev/badge/skills/guyulong/cn-agent-skills/test-gen/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for test-gen

Your own site · 80×15
<a href="https://agentmods.dev/skills/guyulong/cn-agent-skills/test-gen"><img src="https://agentmods.dev/badge/skills/guyulong/cn-agent-skills/test-gen.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 8 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 862 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00008 $0.00862
Opus 5 $0.00004 $0.00431
Sonnet 5 $0.00002 $0.00172
Haiku 4.5 $0.00001 $0.00086

Measured 9d ago against content hash 602a8e3dfe60, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

test-gen scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/test-gen/SKILL.md · 138 lines

How it starts

The opening of the file, as written. The whole thing — 138 lines — stays where its author put it; the contents beside it link to each section on GitHub.

单元测试生成器

使用场景

为函数或类自动生成单元测试代码。

测试框架

Python (pytest)

import pytest
from app.calculator import add, divide

class TestCalculator:
    def test_add_positive(self):
        assert add(1, 2) == 3
    
    def test_add_negative(self):
        assert add(-1, -2) == -3
    
    def test_add_zero(self):
        assert add(0, 0) == 0
    
    def test_divide_normal(self):
        assert divide(10, 2) == 5.0
    
    def test_divide_by_zero(self):
        with pytest.raises(ZeroDivisionError):
            divide(10, 0)
    
    @pytest.mark.parametrize("a,b,expected", [
        (1, 2, 3),
        (0, 0, 0),
        (-1, 1, 0),
        (100, 200, 300),
    ])
    def test_add_parametrize(self, a, b, expected):
        assert add(a, b) == expected

JavaScript (Jest)

const { add, divide } = require('./calculator');

describe('Calculator', () => {
    describe('add', () => {
        test('正数相加', () => {
            expect(add(1, 2)).toBe(3);
        });
        
        test('负数相加', () => {
            expect(add(-1, -2)).toBe(-3);
        });
        
        test('零值相加', () => {
            expect(add(0, 0)).toBe(0);
        });
    });
    
    describe('divide', () => {
        test('正常除法', () => {
            expect(divide(10, 2)).toBe(5.0);
        });
        
        test('除以零抛异常', () => {
            expect(() => divide(10, 0)).toThrow('Division by zero');
        });
    });
});

测试原则

AAA模式

def test_example():
    # Arrange - 准备测试数据
    user = User(name="张三", age=25)
    
    # Act - 执行被测试的操作
    result = user.is_adult()
    
    # Assert - 验证结果
    assert result is True

测试命名规范

# 格式: test_<被测函数>_<场景>_<预期结果>
def test_divide_by_zero_raises_error():
    pass

def test_login_with_wrong_password_returns_error():
    pass

def test_calculate_with_negative_number_returns_positive():
    pass

边界值测试

# 数值边界
def test_boundary():
    assert process(0) == expected  # 最小值
    assert process(MAX_VALUE) == expected  # 最大值
    assert process(-1) == expected  # 负数

# 字符串边界
def test_string_boundary():
    assert process("") == expected  # 空字符串
    assert process("a" * 10000) == expected  # 超长字符串

# 集合边界
def test_collection_boundary():
    assert process([]) == expected  # 空列表
    assert process([1]) == expected  # 单元素

Read the full file on GitHub · 138 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 138 lines · 8 tokens per session scan A 602a8e3dfe60

Subscribe to this mod's changes

test-gen is a skill published in the GitHub repository guyulong/cn-agent-skills (3 stars, last pushed 3mo ago), licensed MIT. It adds 8 tokens to every session and 862 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.