AgentSkillsCN

test

生成覆盖边缘场景、故障模式,并配备恰当模拟手段的全面测试套件。在为函数、类或模块编写测试时,可使用此技能。支持 pytest(Python)、testing 包(Go)、vitest/jest(JS/TS),以及 Rust 内置的测试框架。

SKILL.md
--- frontmatter
name: test
description: Generate comprehensive test suites with edge cases, failure modes, and proper mocking. Use when creating tests for functions, classes, or modules. Supports pytest (Python), testing package (Go), vitest/jest (JS/TS), and built-in test (Rust).

Test Generation

Generate complete test file ready to run.

Coverage Requirements

  • Edge cases: Empty inputs, nil/null, boundary values, zero, negative
  • Failure modes: Invalid inputs, network errors, timeouts, exceptions
  • Boundary conditions: Off-by-one, max/min values, empty collections

Do NOT only test happy path.

Patterns

LanguageFrameworkStyle
Pythonpytest@pytest.mark.parametrize, fixtures, unittest.mock
GotestingTable-driven with t.Run, testify for mocks
JS/TSvitestdescribe/it, vi.mock
Rustbuilt-in#[test], #[should_panic]

Structure (Python)

python
import pytest
from unittest.mock import Mock, patch

@pytest.fixture
def mock_db():
    return Mock()

class TestUserService:
    @pytest.mark.parametrize("email,valid", [
        ("user@example.com", True),
        ("invalid", False),
        ("", False),
    ])
    def test_validate_email(self, email, valid):
        assert validate_email(email) == valid

    def test_create_user_duplicate_raises(self, mock_db):
        mock_db.exists.return_value = True
        with pytest.raises(DuplicateError):
            create_user(mock_db, "existing@example.com")

Output

Complete test file with imports, fixtures, mocks, and all test cases.