Rightpoint / ios-template

A `cookiecutter` template for iOS projects
MIT License
94 stars 26 forks source link

Code Coverage Reports #93

Closed chrisballinger closed 6 years ago

chrisballinger commented 6 years ago

Code Coverage

Codecov

You can use Codecov automatically as long as the repository's owner is a paid Codecov member (assuming this is a private repo).

xcov

xcov generates nicely formatted HTML code coverage reports, and is triggered with every fastlane test. The results are located in the app/build/xcov folder, just open index.html. When run on CircleCI they stored as build artifacts.

xcov also works with Danger to provide code coverage feedback on every pull request. You can also trigger it manually. The include_targets filtering is to exclude external stuff like CocoaPods, but for some reason thinks the target product name for debug-PRODUCTNAME is develop-PRODUCTNAME.app.

You should add other internal frameworks to include_targets inside the Dangerfile and Fastfile as development progresses.

# Manually

# fastlane will run xcov for you
$ bundle exec fastlane test

# when run manually, you must first build via `fastlane test` to generate Xcode's internal code coverage reports
$ bundle exec xcov -w app/PRODUCTNAME.xcworkspace/ -s debug-PRODUCTNAME --include_targets "develop-PRODUCTNAME.app, Services.framework" -o app/build/xcov
# Fastfile
  xcov(
    workspace: "PRODUCTNAME.xcworkspace",
    scheme: "debug-PRODUCTNAME",
    output_directory: "#{ENV['RZ_TEST_REPORTS']}/xcov",
     # For some reason coverage is on the "develop-" app target instead of "debug-"
    include_targets: "develop-PRODUCTNAME.app, Services.framework",
  )
# Dangerfile
xcov.report(
  workspace: "#{src_root}/PRODUCTNAME.xcworkspace",
  scheme: "debug-PRODUCTNAME",
  output_directory: "#{ENV['RZ_TEST_REPORTS']}/xcov",
   # For some reason coverage is on the "develop-" app target instead of "debug-"
  include_targets: "develop-PRODUCTNAME.app, Services.framework",
  ignore_file_path: "#{src_root}/fastlane/.xcovignore"
) 

Slather

Slather is an alternative to xcov and is capable of generating more comprensive HTML reports (located in app/build/slather), as well as uploading to a number of code coverage services like Codecov and Coveralls. It is also integrated into fastlane test but you can run it manually.

There is a similar issue to xcov where the scheme for the app target cannot be found, so right now only Services is included.

# Using fastlane
$ bundle exec fastlane test

# Manually run and open HTML report
$ bundle exec slather coverage --show --html --scheme Services --workspace app/PRODUCTNAME.xcworkspace/ --output-directory app/build/slather app/PRODUCTNAME.xcodeproj/
# Fastfile

slather(
    proj: "PRODUCTNAME.xcodeproj",
    workspace: "PRODUCTNAME.xcworkspace",
    # Only the Services scheme seems to work. It cannot find our app target schemes. 
    scheme: "Services",
    output_directory: "#{ENV['RZ_TEST_REPORTS']}/slather",
    html: "true",
)
raizlabs-oss-bot commented 6 years ago
1 Warning
:warning: Big PR
2 Messages
:book: xcov
:book: Slather

Current coverage for Services.framework is 68.68%

No files affecting coverage found


Current coverage for develop-PRODUCTNAME.app is 1.90%

No files affecting coverage found


Powered by xcov

Generated by :no_entry_sign: Danger

chrisballinger commented 6 years ago

@ZevEisenberg Updated PR with your feedback