Communitygithub.com

ComeOnOliver/skillshub

分析測試覆蓋率缺口,並針對未測試的程式碼路徑建議測試案例。當使用者要求測試改進、覆蓋率分析或希望提升測試覆蓋率時使用。

skillshub 是什麼?

此技能旨在幫助開發者和 AI 代理分析專案的測試覆蓋率,找出未測試的程式碼區塊,並生成具體的測試案例建議。它支援多種程式語言和測試框架,包括 JavaScript/TypeScript(Jest、Mocha、Vitest)、Python(pytest、unittest)、Ruby(RSpec、Minitest)、Go 和 Java(JUnit、JaCoCo)。技能流程包含:偵測測試框架、定位覆蓋率報告(如 lcov.info、coverage.json)、解析覆蓋率資料、優先排序覆蓋率缺口、分析未測試路徑、並生成格式化的測試建議。它也提供可選的測試樁建立功能,協助使用者快速填充測試。透過計算整體覆蓋率指標和風險優先級排序,此技能能有效指導使用者優先測試關鍵業務邏輯、錯誤處理路徑和邊界條件,提升程式碼品質。

相容平台~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% 覆蓋率)- 中優先順序
   - 缺少:無效 token 處理
   - 缺少:過期 session 測試

建議的測試案例:
[每個檔案的詳細建議]

最佳實務

  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

相關技能