查看 Swift 代码的测试覆盖率的开源项目
A tool to generate test code coverage information for Swift.
swiftcov command line tool by running
git clone for
this repo followed by
make install in the root directory.
$ 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
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
--output parameter to specify a destination directory
for the coverage files. If you think the coverage generation process is
slow, you can specify the
threshold option. 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
--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.
Display general or command-specific help.
Display the current version.
$ 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!
Convert to HTML output with Gcovr
$ gcovr --root . --use-gcov-files --html --html-details --output coverage.html --keep
SwiftCov traces the execution of your test code using LLDB by following these steps:
- Set breakpoints in all lines of target's source code. (Those breakpoints only record when they are triggered. They do not stop the tests from running.)
- Run the tests with LLDB attached.
- After the tests have completed, collect the number of times each breakpoint
was hit and generate
.gcovfiles from those results.
- Running on iOS devices is not supported (Simulator or OS X only)
- Application projects are not supported (Framework projects only)
- Running on Travis CI is not supported (It works on Circle CI!)
- Debugging SwiftCov is not supported. If you launch SwiftCov from Xcode, it may fail. github.com/realm/Swift…
- Make sure you do not debug for the same target. It may fail since multiple debuggers cannot attach same target.