生成Xcode Projects的測試覆蓋報告,並將其掛接到CI中。
專案 | 覆蓋範圍 |
---|---|
parsimmon | |
vencore | |
dazabtest | |
tbstatemachine |
將此行添加到您的應用程序的gemfile:
寶石'slather'
然後執行:
$捆綁
或安裝寶石:
寶石安裝slather
編輯方案時,通過勾選“收集覆蓋數據”複選框來啟用測試覆蓋:
要驗證您準備生成測試覆蓋範圍,請在項目上運行測試套件,然後運行:
$ slather覆蓋範圍-s -scheme yourxcodeschemename路徑/to/project.xcodeproj
如果您使用XCode中的工作區,則需要指定它:
$ slather覆蓋範圍-s -scheme yourxcodeschemename -workspace path/to/workspace.xcworkspace path/to/project.xcodeproj
如果您使用其他配置進行測試:
$ slather覆蓋範圍-s -scheme yourxcodeschemename -configuration yourbuildConfigurationName path/to/project.xcodeproj
如果您的配置產生了通用二進製文件,則需要指定要使用的特定體系結構:
$ slather Coverage -s -ark x86_64 -scheme yourxcodeschemename -configuration yourbuildConfigurationName path/to/project.xcodeproj
如果您想運行一些模塊,但不是全部(例如由Cocoapods創建的模塊),您可以這樣做:
$ slather覆蓋範圍-Binary-Basename Module1-Binary-Basename Module2 Path/to/project.xcodeproj
您也可以將其添加到.slather.yml
文件中,作為數組:
binary_basename: - 模塊1 - 模塊2
運行此命令以啟用您項目的Generate Test Coverage
和Instrument Program Flow
標誌:
$ slather設置路徑/到/project.xcodeproj
當使用配置文件( .slather.yml
)和通過命令行提供參數時,參數將優先於配置文件中的匹配設置。
ignore
總是贏得source-files
在定義應忽略的兩個文件( --ignore
,忽略)和源文件以包含( --source-files
,source_files)時,首先檢查忽略列表。如果掃描該文件匹配忽略列表中的一個地球,則不會包含它。在這種情況下,未檢查source_file列表。
如果掃描的文件不在“忽略”列表中,並且已定義了source_file,則將選中source_file列表。如果源文件匹配一個地球,則將包括在內。
登錄到CodeCov(無需激活存儲庫,這會自動發生)。目前, slather
通過此處列出的所有支持的CI提供商支持Codecov。
製作.slather.yml
文件:
#.slather.ymlcoverage_service:cobertura_xmlxcodeproj:path/to/to/project.xcodeprojscheme:yourxcodeschemenameconfiguration:testedconfigurationsource_directory:path/to/conse/to/to/to/source/to/counce outces outces/to/incruppeoutoutountuptut_dectory:path_decign/xml_/ xml to/xml_ml:cml:cml:cml:cml:cml_ml to/xml: - 示例podcode/* -Project -TestSgroup/*
然後在您的.travis.yml
, circle.yml
(或其他CI提供者的測試命令之後),在成功的構建後致電slather
:
#.travis.ymlbefore_install:rvm使用$ rvm_ruby_versionInstall:bundle install -without = documentation -path ../ travis_bundle_dirafter_success: - sl -bash <(curl -s https://codecov.io/bash)-f Path/to/xml_report/cobertura.xml -x Coveragepy -x coveragepy -x gcov -x gcod -x xcode
#circle.ymltest:發布: - 捆綁exec slather-bash <(curl -s https://codecov.io/bash)-f Path/to/xml_report/cobertura.xml -x cubsegagepy -x gcove -x gcove -x xcode
私人倉庫?添加
-t :uuid-repo-token
to codecov上傳器。在此處閱讀有關上傳報告的更多信息
登錄以放入並啟用您的存儲庫。目前, slather
通過Travis CI,Circleci,Jenkins,Teamcity,Buildkite和Bitrise支持下班。
製作.slather.yml
文件並指定您正在使用的CI服務:
#.slather.ymlci_service:CircleCi | travis_ci | travis_pro |詹金斯| buildkite | TeamCityCoverage_service:CoverallSxCodeProj:path/to/project.xcodeprojscheme:yourxcodeschemenameignore: - 示例podcode/* -Project -TestSgroup/*
然後在您的.travis.yml
或circle.yml
或github-action.yml
中,成功構建後致電slather
:
#.travis.ymlbefore_install:rvm使用$ rvm_ruby_versionInstall:bundle install -without = documentation -path ../ travis_bundle_dirafter_success:slather:slather:slather
#circle.ymltest:發布: - 捆綁執行slather
#github-action.yml myjob:步驟: - 運行:| 捆綁配置路徑供應商/捆綁捆綁安裝- without = document = documentation -jobs 4- retry 3-名稱:提取分支nameshell:bashrun:echo:echo“ ## [set -out -output name = branch = branch;] $ (echo $ {github_ref#{github_ref# refs/head/})” id:get_branch-運行:捆綁exec slatherenv:git_branch:$ {{steps.gets.get_branch.outputs.branch}} ci_pull_request:$ {{github.event .event.number}} coveral_access_access_token:$ {number}} covery_access_token:$ { github_token}}}
要使用Travis CI Pro(用於私人存儲庫)的地下室,請在.slather.yml
中添加以下行以及其他設置:
#.slather.ymlci_service:travis_procoverage_access_token:<您的訪問token>
可以在Coveralls Repo頁面上找到覆蓋範圍令牌。否則可以通過COVERAGE_ACCESS_TOKEN
環境將其傳遞。
要創建一個Cobertura XML報告將cobertura_xml
設置為.slather.yml
中的覆蓋範圍服務。您可以選擇為XML報告定義輸出目錄:
#.slather.ymlcoverage_service:cobertura_xmlxcodeproj:path/to/to/project.xcodeprojscheme:yourxcodeschemenamesource_directory:path/to/to/to/to/to/to/to/to/include unclude outtutput_directory:path/to/xml_reportignore:path/ xml_reportignore:path/xml_reportignore: - 示例podcode/* -Project -TestSgroup/*
或使用命令行選項--cobertura-xml
或-x
和--output-directory
:
$ slather Coverage -x -Output -directory Path/to/xml_report
要以靜態HTML頁面創建報告,請使用命令行選項--html
:
$ slather覆蓋範圍 - html -scheme yourxcodeschemename path/to/project.xcodeproj
這將使您的根目錄中的名為html
的目錄(除非指定--output-directory
),並將所有報告作為靜態HTML頁面生成目錄內的靜態HTML頁面。默認情況下,它將打印出報告的路徑,但您也可以指定--show
標誌以自動在瀏覽器中打開。
默認情況下,生成的HTML將引用本地託管資產(JS,CSS)。您可以指定--cdn-assets
,以指定您更喜歡生成的HTML使用外部託管資產。如果將HTML文件作為構建工件發布,這將很有用。
向TeamCity報告覆蓋範圍統計信息:
$ slather覆蓋範圍-Teamcity -S -Scheme yourxcodeschemename
如果您試圖計算通過Cocoapods包含的代碼的覆蓋範圍,則需要告訴Cocoapods通過將以下內容添加到您的Podfile
中,以使用Slather插件。
插件'slather'
您還需要告訴Slather在哪裡可以找到POD的源文件。
#.slather.ymlsource_directory:pods/afnetworking
默認情況下,Slather將在DerivedData
中查找測試覆蓋範圍文件。如果將構建輸出發送到自定義位置,則還應在.slather.yml
中設置build_directory
屬性
如果您在工作區中構建項目,請包括--workspace
參數或將workspace
添加到.slather.yml
。例如:
$ slather覆蓋範圍 - html -scheme yourxcodeschemename -workspace路徑/to/workspace.xcworkspace path/to/project.xcodeproj
我們很想看到您改善該圖書館的想法!最好的貢獻方法是提交拉動請求。我們將盡力盡快響應您的補丁。如果發現錯誤或有疑問,也可以提交新的GitHub問題。
請確保遵循我們的一般編碼樣式,並為新功能添加測試覆蓋範圍!
@tpoulos,完美的徽標。
@Ayanonagon和@kylef,反饋和測試。
@Jhersh,Circleci支持。
@tarbrain,Cobertura的支持和錯誤裝飾。
@ikhsan,HTML支持。
@martin-key和@troyfontaine,GitHub Actions支持。