Skills: Automated Testing Skills

Last updated: 2026-08-31

Tests are the safety net for code — Skills make the net faster to weave, tighter, and smarter.


1. Testing Skill Types

(1) Test Generation

Auto-generate tests from source code:

YAML
---
name: test-generator
description: "Auto-generate unit tests"
triggers:
  - keyword: "generate-test"
tools:
  - Read
  - Grep
  - Glob
  - Write
---
MARKDOWN
## Generation Flow
1. Read source file, analyze function signatures and logic
2. Identify boundary conditions and exception paths
3. Write to create test file
4. Bash to run tests for verification

(2) Test Execution

Auto-detect and run project tests:

Framework Detection Method Run Command
pytest pyproject.toml pytest
Jest package.json npx jest
Go go.mod go test ./...
Rust Cargo.toml cargo test

(3) Failure Diagnosis

Auto-analyze causes when tests fail:

MARKDOWN
## Diagnosis Flow
1. Read failed test output
2. Locate failed assertions and error stacks
3. Read related source code
4. Analyze failure cause
5. Output diagnosis report and fix suggestions

2. Test Generation Strategy

(1) Function-Level Testing

PYTHON
# Source code
def divide(a: float, b: float) -> float:
    if b == 0:
        raise ValueError("Division by zero")
    return a / b
PYTHON
# Auto-generated tests
def test_divide_normal():
    assert divide(10, 2) == 5.0

def test_divide_negative():
    assert divide(-10, 2) == -5.0

def test_divide_zero():
    with pytest.raises(ValueError):
        divide(10, 0)

def test_divide_float():
    assert divide(7, 2) == 3.5

(2) Test Coverage Dimensions

Dimension Test Type Example
Happy path Normal path Normal input returns expected result
Boundary Boundary conditions Empty string, zero, maximum value
Error path Exception path Invalid input raises expected exception
Concurrency Thread safety Multi-thread access to shared resources

3. Coverage Analysis

(1) Coverage Collection

BASH
# Python
pytest --cov=src --cov-report=term-missing

# JavaScript
npx jest --coverage

# Go
go test -coverprofile=coverage.out ./...

(2) Coverage Report

TEXT 📖 Display only
Coverage Report
├── Total coverage: 72%
├── Uncovered files:
│   ├── src/auth/__init__.py (0%) ← Entry file, needs testing
│   ├── src/utils/validators.py (45%) ← Some functions untested
│   └── src/api/routes.py (60%) ← Error handling not covered
└── Suggestion: Prioritize adding tests for validators.py

4. Testing Skill Practice

▶ Example: TDD Assistant Skill

Alice created a TDD assistant Skill to help the team practice test-driven development:

YAML
---
name: tdd-assistant
description: "TDD assistant: write tests first, then implement"
triggers:
  - keyword: "tdd"
tools:
  - Read
  - Write
  - Edit
  - Bash
---
MARKDOWN
## TDD Flow
1. Understand requirements
2. Write failing test (RED)
3. Bash to confirm test fails
4. Edit to write minimal implementation (GREEN)
5. Bash to confirm test passes
6. Edit to refactor and optimize (REFACTOR)
7. Bash to confirm tests still pass

Bob said: "The biggest enemy of TDD is inertia — Skills codify the process so developers don't have to debate 'tests first or code first' — just follow the flow."


❓ FAQ

Q Is auto-generated test quality sufficient?
A Good enough as a starting point, but boundary conditions and business logic tests need manual supplementation. Skill-generated tests cover happy paths and common boundaries; complex scenarios still need human design.
Q Can Skills auto-fix failing tests?
A They can try, but we recommend diagnosing first then fixing. Simple assertion failures can be auto-fixed; complex logic errors need human confirmation of the fix direction.
Q How to balance test coverage and development speed?
A Core modules target 80%+, utility functions 60%+, new features write critical path tests first then incrementally add.

📖 Summary


📝 Exercises

  1. Basic (⭐): Create a test execution Skill that auto-detects the project test framework and runs tests.
  2. Intermediate (⭐⭐): Create a test generation Skill that generates happy/boundary/exception tests for specified functions.
  3. Advanced (⭐⭐⭐): Create a TDD assistant Skill with a complete RED-GREEN-REFACTOR cycle, outputting a status report at each stage.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏