스킬 bats-testing-patterns
🧪

bats-testing-patterns

안전

使用 BATS 編寫可靠的 Shell 腳本測試

또한 다음에서 사용할 수 있습니다: wshobson

學習全面的 BATS 測試模式,在 CI/CD 流程中編寫可維護、可靠的 Shell 腳本測試。

지원: Claude Codex Code(CC)
🥉 72 브론즈
1

스킬 ZIP 다운로드

2

Claude에서 업로드

설정 → 기능 → 스킬 → 스킬 업로드로 이동

3

토글을 켜고 사용 시작

테스트해 보기

"bats-testing-patterns" 사용 중입니다. 為處理 CSV 檔案的腳本編寫測試

예상 결과:

  • 一個 BATS 測試檔案,包含檔案存在性、內容驗證、畸形 CSV 的錯誤處理以及成功案例的測試

"bats-testing-patterns" 사용 중입니다. 如何測試我的腳本在無效輸入時正確失敗?

예상 결과:

  • 展示 @test 區塊的範例,包含參數缺失、無效選項、權限拒絕情境以及錯誤訊息斷言

"bats-testing-patterns" 사용 중입니다. 為具有多個命令的 CLI 工具設定測試

예상 결과:

  • 測試結構包含輔助函式、固定裝置設定、清理 teardown 以及幫助輸出、版本旗標和主要命令執行的測試

보안 감사

안전
v1 • 2/25/2026

This skill provides documentation and examples for writing BATS tests. All 91 static findings are false positives: external commands are code examples in markdown, network URLs are documentation links, filesystem patterns are legitimate test setup patterns, and weak crypto detection is a false positive due to 'Bats' being misidentified as a cryptographic reference.

2
스캔된 파일
652
분석된 줄 수
0
발견 사항
1
총 감사 수
보안 문제를 찾지 못했습니다
감사자: claude

품질 점수

38
아키텍처
100
유지보수성
87
콘텐츠
31
커뮤니티
100
보안
100
사양 준수

만들 수 있는 것

DevOps 工程師測試基礎設施腳本

為部署腳本、配置管理腳本和基礎設施自動化腳本編寫自動化測試,確保可靠性。

開發者為 Shell 工具新增測試

為 CLI 工具和 Shell 公用程式實作測試驅動開發,儘早發現程式回歸問題。

團隊建立 Shell 腳本品質標準

在團隊中建立全面的測試模式和最佳實踐,維持一致的程式碼品質。

이 프롬프트를 사용해 보세요

基本測試建立
Create a BATS test file for my shell script at script.sh that tests the exit code and output of the main function.
使用固定裝置測試
Write BATS tests that use fixture files from tests/fixtures/ directory to test file processing functions.
模擬外部命令
Show me how to stub the 'curl' command in BATS to test an API function without making real network requests.
CI/CD 整合
Create a GitHub Actions workflow and Makefile to run BATS tests in CI/CD with TAP output.

모범 사례

  • 使用描述性的測試名稱,清楚說明測試內容和預期行為
  • 務必在 teardown 函式中清理臨時檔案和資源,防止測試污染
  • 模擬外部依賴如 API 呼叫和檔案系統操作,以隔離單元測試

피하기

  • 在單一測試函式中測試多個不相關的斷言違反單一職責原則
  • 跳過 teardown 或清理會導致測試不穩定和資源洩漏
  • 測試實作細節而非可觀察行為會使測試變得脆弱

자주 묻는 질문

什麼是 BATS?
BATS(Bash Automated Testing System)是一個用於 Shell 腳本的測試框架,提供符合 TAP 標準的輸出和簡單的測試語法。
如何安裝 BATS?
可透過 Homebrew(brew install bats-core)、npm(npm install --global bats)或從 GitHub 克隆並執行安裝腳本來安裝。
setup 和 setup_file 有什麼區別?
setup() 在每個測試前執行,而 setup_file() 在檔案中所有測試前僅執行一次。對昂貴的共享資源使用 setup_file。
如何測試命令失敗?
使用 'run' 執行命令,然後斷言 $status 為非零,並可選檢查錯誤輸出。
我可以測試使用外部命令的腳本嗎?
可以,使用 'export -f' 進行函式模擬,或透過在臨時 PATH 目錄中建立模擬可執行檔來進行命令樁。
如何平行執行測試?
使用 --parallel 旗標與 bats,例如:bats tests/*.bats --parallel 4

개발자 세부 정보

파일 구조