Token导航 LogoToken导航TokenDH.com
研究检索external-servicegithub未标认证来源可访问许可证需确认审计通过

smart-code-test-unit智能代码测试单元

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

196

周安装

8

GitHub Stars

公开资料未说明

下载量

63
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:smart-code-test-unit(智能代码测试单元)
来源仓库:https://github.com/lordprotein/smart-code-test-unit
仓库路径:skills/smart-code-test-unit
安装命令:
npx skills add https://github.com/lordprotein/smart-code-test-unit --skill smart-code-test-unit
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/lordprotein/smart-code-test-unit --skill smart-code-test-unit

简介

smart-code-test-unit 用于辅助测试设计、自动化测试和回归验证,帮助编写单元测试或端到端测试。

  • 适用于根据失败日志定位问题、生成测试计划或整理用例的场景。
  • 使用时需确认项目测试框架、运行命令和夹具数据配置。
  • 涉及浏览器或外部服务时,应区分本地模拟与生产环境,避免误改真实逻辑。
  • 不能仅依赖工具输出作为最终结论,需人工复核测试有效性。

SKILL.md

Unit Test Expert

Overview

Generate high-quality unit tests or review existing tests using industry best practices. Works in two modes:

  • Mode 1: Generate Tests — analyze code and produce comprehensive tests
  • Mode 2: Review Tests — evaluate existing tests for quality, coverage, and antipatterns

Default to Generate mode unless the user explicitly asks to review existing tests or the input is clearly test code.

Scope

This skill is focused exclusively on unit testing:

  • Tests one unit in isolation (function, class, component)
  • Dependencies are mocked, stubbed, or faked
  • No E2E tests, no full integration tests spanning multiple real services
  • "Integration" within unit scope is acceptable: e.g., testing a component with its simple presentational children, or a service with an in-memory repository

Severity Levels

LevelNameDescriptionAction
P0CriticalFalse confidence — test passes but doesn't verify correctnessMust fix immediately
P1HighMajor quality issue — fragile, over-mocked, missing critical coverageShould fix before merge
P2MediumMaintainability concern — readability, naming, structureFix in this PR or follow-up
P3LowStyle or minor suggestionOptional improvement

Mode 1: Generate Tests

0) Determine test scope

MANDATORY — you MUST perform this step BEFORE preflight. Do NOT skip it.

  • Analyze the target code and determine which categories are present:

- Business logic / domain model — core rules, algorithms, calculations, state machines - UI components — components that render UI, handle user interactions, manage visual state - Utilities / helpers / hooks — pure functions, transformers, validators, formatters, parsers, hooks/composables

  • Ask the user (multiselect) which types of tests to generate:

- Unit tests for business logic - Unit tests for UI components - Unit tests for utilities / hooks

  • If the code clearly belongs to only one category, still confirm with the user before proceeding.
  • Generate only the selected categories — do NOT generate tests for unselected categories.

1) Preflight context

  • Use git status -sb, git diff --stat, and git diff to scope changes. If user specifies files, analyze those instead.
  • Identify the programming language, test framework, and assertion library used in the project.
  • Search for existing tests (rg -g "*test*" -g "*spec*" --files) to discover:

- Test directory structure and file naming conventions - Test framework and assertion patterns in use - Helper functions, builders, fixtures, or factories already defined - Naming conventions for test methods

  • If no existing tests found, ask user about preferred framework or propose a standard one for the language.

Edge cases:

  • No changes: If git diff is empty, ask user which files/modules to generate tests for.
  • Large diff (>500 lines): Summarize modules first, then ask user to prioritize which to test.
  • Test files in diff: Switch to Mode 2 (Review) for the test files, Mode 1 for production files.

2) Classify code (Khorikov matrix)

MANDATORY — you MUST load and apply the classification matrix. Do NOT skip this step, do NOT generate tests without classifying first.

  • Load references/testing-principles.md for the classification matrix.
  • Categorize each unit of code:
CategoryTest strategy
Domain model / algorithmsUnit test extensively — highest priority
UI componentTest rendering, interactions, states, a11y (if selected in step 0)
Utility / pure function / hookOutput-based testing, parameterized tests (if selected in step 0)
Trivial code (getters, DTOs, one-line delegations)Skip — no tests needed
Controllers / orchestratorsIntegration tests only — don't unit test
Overcomplicated code (high complexity + many dependencies)Recommend refactoring first, then test
  • Report the classification to the user before generating tests.
  • If code is overcomplicated, suggest applying Humble Object pattern to extract testable logic.

3) Determine test scenarios

MANDATORY — you MUST load scenario identification techniques before determining scenarios. Do NOT rely on general knowledge alone.

  • Load references/business-logic-testing.md for scenario identification techniques.
  • For each domain logic unit, identify:

- Happy paths: Core business rules, primary use cases - Decision table scenarios: All condition combinations for complex rules - Boundary conditions: Min, max, zero, empty, null, off-by-one - Error paths: Invalid input, constraint violations, exception handling - Invariants: Conditions that must always hold after any operation - State transitions: Valid and invalid transitions (if applicable)

  • Prioritize: business-critical paths first, edge cases second, defensive checks last.

4) Generate tests

MANDATORY — you MUST load the reference files listed below before generating any test code.

  • Load references/test-design-patterns.md for patterns.
  • Load references/test-doubles-guide.md for double selection.
  • If UI component tests selected → also load references/ui-component-testing.md for UI-specific principles, query priority, snapshot rules, and UI antipatterns.
  • If utility / hooks tests selected → also load references/utility-and-hooks-testing.md for parameterized testing, boundary analysis, hooks testing strategies, and utility antipatterns.
  • Apply these rules:

Structure:

  • Follow AAA pattern (Arrange-Act-Assert) with clear visual separation
  • One Act per test — never test multiple behaviors in one test
  • No conditional logic in tests (no if/for/try-catch)
  • Group tests logically (by behavior/feature, using describe/context if framework supports)

Naming:

  • Use project's existing naming convention if detected
  • Otherwise use descriptive names: test_[scenario]_[expected_result] or test_[behavior_description]
  • Name must describe WHAT is tested and WHAT the expected outcome is
  • Use domain language, not implementation terms

Test doubles:

  • Default to real objects for in-process dependencies
  • Use stubs only when real setup is impractical and behavior is irrelevant to this test
  • Mock ONLY unmanaged out-of-process dependencies (external APIs, SMTP, payment gateways)
  • Create adapters/wrappers for third-party libraries — never mock what you don't own
  • Prefer fakes over mocks when dependency has complex behavior

Data setup:

  • Use builders/factories if they exist in the project
  • Create new builders if the same object setup repeats 3+ times
  • Use parameterized tests for decision tables and boundary value sets
  • Every magic value in a test should have a clear purpose (via variable name or context)

Typing (TypeScript / typed languages):

  • Always use real types from the project — import and reuse existing interfaces, types, enums
  • If the real type is not found — use unknown, never any
  • any is forbidden unless there is absolutely no other option

Assertions:

  • Assert on specific expected values, not just is not None or doesn't throw
  • For error paths, assert on system state AFTER the error (not just the exception)
  • One logical concept per test (may be multiple assert statements)
  • Use the project's assertion style (expect/assert/should)

5) Self-check against antipatterns

MANDATORY — you MUST load the antipatterns checklist and run EVERY check below for EACH generated test. Do NOT output tests without completing this verification.

  • Load references/antipatterns-checklist.md.
  • Before outputting, verify each generated test against:

- Not a Liar — has meaningful assertions - Not a Giant — single Act, focused assertions - Not a Mockery — minimal, justified mocks - Not an Inspector — tests public behavior only - Not Fragile — would survive refactoring - No shared mutable state - No conditional logic - Not testing trivial code

  • If any check fails, fix the test before outputting.

6) Output format

## Test Generation Summary

**Source**: X files analyzed, Y functions/methods identified
**Classification**: Domain logic: A, UI components: B, Utilities/hooks: C, Trivial (skipped): D, Controllers (skip for unit test): E
**Tests generated**: Z test cases

---

## Code Classification

> **Required.** Classify every analyzed function/method before generating tests.

| File / Function | Category | Test strategy |
|----------------|----------|---------------|
| (list each unit) | Domain model / UI / Utility / Trivial / Controller / Overcomplicated | Unit test / UI test / Output-based / Skip / Integration / Refactor first |

---

## Generated Tests

### [filename_test.ext]

[Test code with comments explaining the scenario for non-obvious cases]

---

## Coverage Notes

- **Tested**: business rules, UI components, utilities/hooks covered
- **Not tested (trivial)**: skipped trivial code
- **Out of scope**: controllers (integration), overcomplicated (refactor first)

---

## Next Steps

1. **Run tests** — Shall I run the generated tests to verify they pass?
2. **Add more scenarios** — Any edge cases or business rules I missed?
3. **Create test helpers** — Shall I extract builders/factories for reusable setup?

Important: Do NOT write test files to disk until user explicitly confirms. Present the generated tests in the output first, then ask how to proceed.


Mode 2: Review Tests

1) Preflight context

  • Collect existing test files: from git diff or user-specified files.
  • Identify test framework, assertion library, and project conventions.
  • Read the corresponding production code to understand what's being tested.

Edge cases:

  • No test files found: Inform user and offer to switch to Mode 1 (Generate).
  • Mixed test and production code in diff: Review tests (Mode 2), generate tests for uncovered production code (Mode 1).

2) Evaluate against checklist

MANDATORY — you MUST load ALL THREE reference files below. Do NOT evaluate from memory alone.

  • Load references/test-review-checklist.md for the full checklist.
  • Load references/antipatterns-checklist.md for antipattern detection.
  • Load references/test-doubles-guide.md for doubles assessment.

MANDATORY procedure — follow this exact sequence for every review. Do NOT skip steps or merge findings:

  1. Scan for Liars (P0) — meaningful assertions in every test?
  2. Check isolation (P0) — shared mutable state?
  3. Check doubles usage (P1) — over-mocking? mocking internals?
  4. Check fragility (P1) — behavior or implementation verification?
  5. Check coverage quality (P1) — critical paths tested?
  6. Check readability (P2) — names, AAA structure, clarity
  7. Check speed (P2) — unnecessary delays or real I/O?
  8. Check for trivial tests (P3) — testing getters/constructors?

3) Assess severity

Assign severity to each finding using the severity levels defined above (P0-P3).

4) Output format

## Test Review Summary

**Files reviewed**: X test files, Y test cases
**Overall assessment**: [APPROVE / REQUEST_CHANGES / COMMENT]
**Coverage quality**: [Good / Adequate / Insufficient]

---

## Findings

### P0 - Critical
(none or list)

### P1 - High
1. **[test_file:line]** Brief title
   - **Antipattern**: Which antipattern
   - **Problem**: What's wrong
   - **Impact**: Why it matters
   - **Fix**: Suggested correction with code example

### P2 - Medium
2. (continue numbering)

### P3 - Low
...

---

## Coverage Gaps

- [Business rules / paths not covered by any test]

## Positive Observations

- [What's done well — reinforce good practices]

---

## Next Steps

I found X issues (P0: _, P1: _, P2: _, P3: _).

**How would you like to proceed?**

1. **Fix all** — I'll implement all suggested fixes
2. **Fix P0/P1 only** — Address critical and high priority issues
3. **Fix specific items** — Tell me which issues to fix
4. **No changes** — Review complete, no implementation needed

Please choose an option or provide specific instructions.

Important: Do NOT implement any changes until user explicitly confirms. This is a review-first workflow.


Resources

Reference files are in references/. Each step above specifies which files to load.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude

34.64%
按下载量换算22

Codex

33.94%
按下载量换算21

Cursor

18.41%
按下载量换算12

Gemini CLI

10.16%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills