Communitygithub.com

ComeOnOliver/skillshub

分析测试覆盖缺口,并针对未测试的代码路径建议测试用例。当用户请求测试改进、覆盖分析或希望增加测试覆盖率时使用。

skillshub 是什么?

该技能旨在帮助开发者和 AI 代理识别测试覆盖缺口,并生成具体的测试用例建议以提升代码质量。它支持 JavaScript/TypeScript(Jest、Mocha、Vitest、Jasmine)、Python(pytest、unittest、coverage.py)、Ruby(RSpec、Minitest)、Go(内置测试)和 Java(JUnit、JaCoCo)等多种平台和测试框架。技能通过检测项目中的测试框架、定位并解析覆盖率报告(如 lcov.info、coverage.json、.coverage 或 HTML 报告)来工作。然后,它按优先级(业务逻辑、公共 API、错误处理为高优先级)识别缺口,分析未测试的代码路径,并为每个缺口生成包含输入数据、预期行为和覆盖行的详细测试用例建议,最后给出一个清晰的汇总报告,包括总体覆盖率、需关注的文件和优先建议。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/aiskillstore/marketplace/crazydubya/test-coverage-analyzer

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

测试覆盖分析器

此技能有助于识别测试覆盖缺口,并建议具体的测试用例以提升代码质量。

何时使用此技能

  • 用户要求分析测试覆盖率
  • 用户希望改进测试覆盖率
  • 用户请求缺失测试的建议
  • 处理增加代码覆盖率百分比的任务
  • 用户提到“覆盖缺口”、“未测试代码”或“测试建议”

说明

1. 检测测试框架

识别项目中使用的测试框架:

JavaScript/TypeScript:

  • Jest:jest 在 package.json 中或 jest.config.js
  • Mocha:mocha 在 package.json 中或 .mocharc
  • Vitest:vitest 在 package.json 中或 vitest.config.js
  • Jasmine:jasmine 在 package.json 中

Python:

  • pytest:pytest 在 requirements.txt 中或 pytest.ini
  • unittest:标准库,检查测试文件
  • coverage.py:coverage 在 requirements.txt 中

Ruby:

  • RSpec:rspec 在 Gemfile 中
  • Minitest:标准库

Go:

  • 内置:go test(通过 go test -cover 实现覆盖率)

Java:

  • JUnit:在 pom.xml 或 build.gradle 中查找 JUnit
  • JaCoCo:覆盖率工具配置

使用 Glob 和 Grep 查找配置文件。

2. 定位覆盖率报告

查找现有的覆盖率报告:

常见位置:

  • coverage/ 目录
  • .nyc_output/(Node.js 的 NYC)
  • htmlcov/(Python 的 coverage.py)
  • target/site/jacoco/(Java 的 JaCoCo)
  • 覆盖率文件:lcov.info、coverage.json、.coverage

如果没有覆盖率报告:

  • 引导用户运行覆盖率命令:npm test -- --coverage、pytest --cov 等
  • 等待报告生成后再进行分析

3. 解析覆盖率数据

提取覆盖率信息:

从 lcov.info:

  • 覆盖的行数 vs. 总行数
  • 覆盖的函数 vs. 总函数
  • 覆盖的分支 vs. 总分治
  • 每个文件中未覆盖的行号

从 coverage.json(Jest):

  • 语句覆盖率百分比
  • 分支覆盖率百分比
  • 函数覆盖率百分比
  • 行覆盖率百分比
  • 每个文件中未覆盖的行

从 .coverage(Python):

  • 使用 coverage report 或 coverage json
  • 缺失的行范围
  • 排除的行

从 HTML 报告:

  • 读取摘要统计信息
  • 识别覆盖率低的文件

4. 识别覆盖缺口

按优先级排列需要测试的文件/函数:

高优先级:

  • 覆盖率为 0% 的业务逻辑
  • 公共 API 和导出的函数
  • 错误处理路径(catch 块、错误回调)
  • 边界情况与边界条件
  • 关键路径(身份验证、支付、数据验证)

中优先级:

  • 部分覆盖的工具函数
  • 被公共 API 调用的私有函数
  • 配置与初始化代码

低优先级:

  • 简单的 getter/setter
  • 类型定义
  • 自动生成的代码
  • 第三方代码

5. 分析未测试的代码路径

对于每个有覆盖缺口的文件:

  1. 读取源文件以了解代码结构
  2. 识别未测试的代码:
    • 未覆盖的行和行范围
    • 未测试的条件分支(if/else)
    • 未覆盖的错误处理程序
    • 缺失的函数覆盖
  3. 分类缺失的测试:
    • 正常路径测试
    • 错误/异常测试
    • 边界情况测试
    • 集成测试

6. 生成测试建议

对于每个覆盖缺口,建议具体的测试用例:

格式:

文件:src/utils/validator.js(42% 覆盖率)

缺失的覆盖:
- 第 15-18 行:电子邮件验证错误路径
- 第 23-25 行:空输入处理
- 第 30-35 行:特殊字符的边界情况

建议的测试:
1. 使用无效格式测试电子邮件验证(覆盖第 15-18 行)
2. 使用空字符串输入测试验证器(覆盖第 23-25 行)
3. 测试名称中的特殊字符处理(覆盖第 30-35 行)

测试用例详情应包括:

  • 测试描述
  • 输入数据
  • 预期输出/行为
  • 覆盖的行/分支

7. 创建测试桩(可选)

如果用户需要,生成测试文件桩:

  • 使用适当的测试框架语法
  • 包含带有 TODO 注释的 describe/test 块
  • 添加示例测试结构
  • 引用 templates/test-template.js(或相应的扩展名)中的模板

示例(Jest):

describe('Validator', () => {
  describe('validateEmail', () => {
    it('应拒绝无效的电子邮件格式', () => {
      // TODO: 测试电子邮件验证错误路径(第 15-18 行)
      const result = validateEmail('invalid-email');
      expect(result.valid).toBe(false);
    });

    it('应处理空字符串输入', () => {
      // TODO: 测试空输入处理(第 23-25 行)
    });
  });
});

8. 计算覆盖率指标

提供摘要统计信息:

  • 总体覆盖率百分比
  • 按文件/目录的覆盖率
  • 没有测试的函数/方法
  • 覆盖率低的关键文件
  • 覆盖率趋势(如果有历史数据)

9. 按优先级排序建议

按以下顺序排列建议:

  1. 影响:首先处理关键业务逻辑
  2. 风险:高风险领域(安全性、数据完整性)
  3. 复杂度:复杂逻辑需要更多测试
  4. 简便性:快速取胜(简单测试以获得高覆盖率提升)

10. 输出格式

以清晰、可操作的形式呈现发现结果:

覆盖率分析摘要
=========================

总体覆盖率:67%
- 语句:65%
- 分支:58%
- 函数:72%
- 行:67%

需要关注的文件(按优先级排序):

1. src/payment/processor.js(23% 覆盖率) - 高优先级
   - 缺失:付款失败的错误处理
   - 缺失:重试逻辑测试
   - 缺失:交易验证

2. src/auth/validator.js(45% 覆盖率) - 中优先级
   - 缺失:无效令牌处理
   - 缺失:过期会话测试

建议的测试用例:
[每个文件的详细建议]

最佳实践

  1. 关注有意义的覆盖率:100% 的覆盖率并非总是必要
  2. 测试行为,而非实现:建议验证功能的测试
  3. 优先考虑关键路径:首先处理身份验证、支付、数据验证
  4. 考虑测试类型:酌情使用单元测试、集成测试和端到端测试
  5. 检查现有测试:不要建议已经存在的测试
  6. 使用现实的测试数据:在示例中使用合理的输入
  7. 覆盖率阈值:建议最低覆盖率目标(例如 80%)

运行覆盖率报告

根据检测到的框架提供命令:

Jest: npm test -- --coverage 或 jest --coverage Vitest: npm test -- --coverage 或 vitest run --coverage Mocha + NYC: nyc mocha pytest: pytest --cov=src --cov-report=html Go: go test -cover ./... 或 go test -coverprofile=coverage.out JUnit + JaCoCo: mvn test jacoco:report

支持文件

  • scripts/parse-coverage.sh:提取覆盖率数据的辅助脚本
  • templates/test-template.js:JavaScript 的测试文件模板
  • templates/test-template.py:Python 的测试文件模板
  • templates/test-template.go:Go 的测试文件模板

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相关技能