为Swift生成测试代码覆盖信息的工具:SwiftCov

yg3n 9年前

一个工具用于为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.open-open.com/lib/view/home/1433384732666