Giter Site home page Giter Site logo

ikesyo / swiftcov Goto Github PK

View Code? Open in Web Editor NEW

This project forked from realm/swiftcov

0.0 3.0 0.0 111 KB

A tool to generate test code coverage information for Swift.

License: MIT License

Swift 75.91% Makefile 4.21% Python 15.91% Shell 2.46% Ruby 0.48% Objective-C 1.04%

swiftcov's Introduction

SwiftCov

A tool to generate test code coverage information for Swift.

Circle CI Coverage Status

Installation

Install the swiftcov command line tool by running git clone for this repo followed by make install in 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 --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

Options

  • --output OUTPUT_DIR specify output directory for generated coverage files.

  • --threshold LIMIT_COUNT specify the maximum number of hits you wish to measure. Reducing this number can drastically speed up SwiftCov.

  • --debug Output 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.
    e.g.

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

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!

Advanced usage

Convert to HTML output with Gcovr

$ gcovr --root . --use-gcov-files --html --html-details --output coverage.html --keep

See the generated coverage file.

Send coverage information to codecov.io.

Use codecov-bash global uploader.

# cirlce.yml
test:
  override:
    - sudo chown :wheel /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ *.simruntime/Contents/Resources/RuntimeRoot/usr/lib/dyld_sim
    - xcodebuild test -project Example.xcodeproj -scheme 'Example' -configuration Release -sdk iphonesimulator
    - swiftcov generate --output coverage xcodebuild test -project Example.xcodeproj -scheme 'Example' -configuration Release -sdk iphonesimulator
  post:
    - bash <(curl -s https://codecov.io/bash)

Send coverage information to coveralls.io.

Use coveralls-gcov.

# Gemfile
source "https://rubygems.org"

gem "coveralls-gcov"
# cirlce.yml
dependencies:
  override:
    - bundle install
test:
  override:
    - sudo chown :wheel /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ *.simruntime/Contents/Resources/RuntimeRoot/usr/lib/dyld_sim
    - xcodebuild test -project Example.xcodeproj -scheme 'Example' -configuration Release -sdk iphonesimulator
    - swiftcov generate --output coverage xcodebuild test -project Example.xcodeproj -scheme 'Example' -configuration Release -sdk iphonesimulator
  post:
    - bundle exec coveralls-gcov --repo-token REPO_TOKEN --no-gcov

How SwiftCov works

SwiftCov traces the execution of your test code using LLDB by following these steps:

  1. 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.)
  2. Run the tests with LLDB attached.
  3. After the tests have completed, collect the number of times each breakpoint was hit and generate .gcov files from those results.

Limitations

  • 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. realm#6
  • Make sure you do not debug for the same target. It may fail since multiple debuggers cannot attach same target.

License

MIT licensed.

swiftcov's People

Contributors

ikesyo avatar jpsim avatar kishikawakatsumi avatar stephencelis avatar stevepeak avatar thomvis avatar yoavlt avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.