技能 unit-testing-test-generate
📦

unit-testing-test-generate

安全

自動生成全面的單元測試

手動編寫單元測試既耗時又容易出錯。此技能可跨多種語言和框架自動化測試生成,涵蓋邊緣案例並提供適當的模擬功能。

支援: Claude Codex Code(CC)
📊 71 充足
1

下載技能 ZIP

2

在 Claude 中上傳

前往 設定 → 功能 → 技能 → 上傳技能

3

開啟並開始使用

測試它

正在使用「unit-testing-test-generate」。 為具有 add、subtract、multiply 函式的計算機模組生成 pytest 測試

預期結果:

包含 TestCalculator 類別的測試檔案,內含每個操作的參數化測試、零和負數的邊緣案例,以及型別錯誤處理

正在使用「unit-testing-test-generate」。 為帶有 mock fetch 的非同步 API 用戶端建立 Jest 測試

預期結果:

包含模擬 fetch 回應的測試套件、成功和錯誤狀態的測試、正確的 async/await 模式,以及逾時處理

安全審計

安全
v1 • 2/25/2026

Static analysis detected 31 patterns but all are false positives. The skill is documentation-only containing code examples in markdown format. The subprocess.run pattern is legitimate test coverage functionality. Cryptographic warnings are Jest describe() functions. No executable code poses security risks.

1
已掃描檔案
322
分析行數
0
發現項
1
審計總數
未發現安全問題
審計者: claude

品質評分

38
架構
100
可維護性
87
內容
33
社群
100
安全
91
規範符合性

你能建構什麼

為新專案快速建立測試套件

在開始新程式碼庫或為沒有現有測試的舊版程式碼新增測試時,快速啟動全面的測試覆蓋。

在重構期間維持測試覆蓋率

在重大程式碼變更後重新生成測試,確保覆蓋率保持高水平且邊緣案例仍經驗證。

透過範例學習測試最佳實踐

研究生成的測試以了解適合您框架的正確模擬策略、斷言模式和測試組織方式。

試試這些提示

基本 Python 測試生成
Generate pytest unit tests for the Python module at ./src/utils.py. Include tests for all public functions with happy path and error cases.
JavaScript Jest 測試套件
Create Jest tests for the functions in ./helpers/validation.js. Use proper mocking for external API calls and include edge cases for null and undefined inputs.
React 元件測試
Generate React component tests for ./components/UserProfile.tsx using Testing Library. Test rendering, props handling, and user interactions like button clicks.
覆蓋率缺口分析和測試生成
Analyze coverage report from ./coverage/coverage.json and generate targeted tests for all uncovered lines in the src/models/ directory. Focus on boundary conditions and exception handling.

最佳實務

  • 務必審查生成的測試,確保斷言驗證了正確的預期行為
  • 新增自動化分析可能無法偵測到的領域特定邊緣案例
  • 在提交前立即執行生成的測試以驗證其通過

避免

  • 不要在未審查和理解每個斷言的情況下提交生成的測試
  • 避免為快速變動的程式碼生成測試 - 請等待穩定後再進行
  • 不要僅依賴生成的測試進行安全關鍵或財務計算的驗證

常見問題

支援哪些程式語言?
主要支援 Python (pytest)、JavaScript 和 TypeScript (Jest)。也涵蓋 Java (JUnit) 和 Go (testing package),並提供框架特定的模式。
此技能可以測試私有方法嗎?
此技能專注於公開 API 測試。私有方法應透過公開方法測試間接驗證。通常不建議直接測試私有方法。
如何在生成的測試中處理資料庫相依性?
此技能會為資料庫連線生成模擬 fixture。對於需要真實資料庫的整合測試,您需要手動新增資料庫設定和清理。
生成的測試能與我現有的 CI 流程搭配使用嗎?
是的,生成的測試使用標準框架慣例,與常見的 CI 工具(如 GitHub Actions、Jenkins 和 GitLab CI)相容。
如何驗證生成測試的品質?
在執行生成的測試後執行您的覆蓋率工具。以高陳述句和分支覆蓋率為目標。審查斷言是否檢查了有意義的條件。
此技能可以更新現有的測試檔案嗎?
此技能生成新的測試程式碼。您可以手動將生成的測試與現有檔案合併,或為新功能建立獨立的測試模組。

開發者詳情

檔案結構

📄 SKILL.md