為Swift生成測試代碼覆蓋信息的工具:SwiftCov

yg3n 9年前發布 | 14K 次閱讀 SwiftCov Apple Swift開發

一個工具用于為Swift生成測試代碼覆蓋信息。

Installation

Install theswiftcovcommand line tool by runninggit clonefor this repo followed bymake installin the root directory.

Usage

$ swiftcov help
Available commands:

   generate   Generate test code coverage files for your Swift tests
   help       Display general or command-specific help
   version    Display the current version of SwiftCov


generate

Run the tests and generate code coverage files. You can write any xcodebuild command as arguments for testing your project.

$ swiftcov generate
Usage: swiftcov generate [swiftcov options] xcodebuild [xcodebuild options] (-- [swift files])

$ swiftcov generate \
  xcodebuild test \
  -project Example.xcodeproj -scheme 'Example' \
  -configuration Release -sdk iphonesimulator

Use the--outputparameter to specify a destination directory for the coverage files. If you think the coverage generation process is slow, you can specify thethresholdoption. It makes running faster to limit the count of the number of executions.

Currently, the default value of threshold option is 1 for performance reasons. Since some test cases may take a very long time generating coverage data, especially if some code paths are frequently hit (as is the case with loops).

$ swiftcov generate --output ./coverage --threshold 1 \
  xcodebuild test \
  -project Example.xcodeproj -scheme 'Example'
  -configuration Release -sdk iphonesimulator

Options

  • --output OUTPUT_DIRspecify output directory for generated coverage files.
  • --threshold LIMIT_COUNTspecify the maximum number of hits you wish to measure. Reducing this number can drastically speed up SwiftCov.
  • --debugOutput very verbose progress messages.
  • -- [swift files]Pass a space-separated list of files for which to measure code coverage, with either relative or absolute paths, after the--at the end of your command.

help

Display general or command-specific help.

version

Display the current version.

How to run example project

$ make install
$ cd Examples/ExampleFramework/
$ swiftcov generate --output coverage_ios \
  xcodebuild test \
  -project ExampleFramework.xcodeproj \
  -scheme ExampleFramework-iOS \
  -sdk iphonesimulator \
  -configuration Release

Please see the generated coverage file!


項目主頁:
http://www.baiduhome.net/lib/view/home/1433384732666

 本文由用戶 yg3n 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!