AgentSkillsCN

testability

在代码评审过程中,以可测试性为核心评估标准。无论是新编写的待测代码,还是在评估依赖注入、全局状态、纯函数以及测试钩子等设计时,都应将可测试性作为重要考量因素。

SKILL.md
--- frontmatter
name: testability
version: 1.1.0
description: Testability assessment criteria for code review. Apply when writing new code that will be tested or evaluating code for dependency injection, global state, pure functions, and test seams.
user-invocable: false
layers:
  rules: rules.md
  examples: examples.md

Testability Assessment

Evaluate whether code can be effectively unit tested in isolation.

Layers:

  • rules.md - Quick reference and severity guidance
  • examples.md - Detailed code examples

Quick Reference

FactorQuestionSeverity if problematic
Dependency injectionAre deps passed in?High
Global stateIs shared state avoided?High
Pure functionsIs logic separated from I/O?Medium
Time/randomnessAre these injectable?Medium
File systemCan it be abstracted?Medium
SeamsCan behavior be substituted?Medium-High
ObservabilityCan you assert on outputs?Medium

Quick Heuristic

If testing a function requires:

  • 0 mocks: Excellent testability (pure function)
  • 1-2 mocks: Good testability (clear dependencies)
  • 3-5 mocks: Concerning (might need refactoring)
  • 6+ mocks: Likely design problem (too many responsibilities)

For rules: see rules.md For examples: see examples.md