Skip to content

Add coverage reporting to CI #793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
paulb777 opened this issue Feb 14, 2018 · 13 comments
Closed

Add coverage reporting to CI #793

paulb777 opened this issue Feb 14, 2018 · 13 comments

Comments

@paulb777
Copy link
Member

Investigate a solution like https://github.com/SlatherOrg/slather and report coverage for the travis unit test runs.

@wilhuff
Copy link
Contributor

wilhuff commented Feb 14, 2018

I recently got this partially working for Firestore (not the Travis part)

slather coverage -s
  -i 'Firestore/third_party/abseil-cpp/*'
  -i 'Firestore/Example/*'
  -i 'Firestore/Protos/*'
  --configuration=Debug --scheme=AllTests
  --workspace=Firestore/Example/Firestore.xcworkspace
  --binary-file $HOME/Library/Developer/Xcode/DerivedData/Firestore-byuxnozrvymsezgkpumlkvgmfmtu/Build/Products/Debug-iphonesimulator/Firestore_Example.app/Firestore_Example
  Firestore/Example/Firestore.xcodeproj

Unfortunately there's a problem in the interaction between Xcode 9 and slather that's preventing it from finding the binary based on the configuration and I wasn't able to spend more time figuring out what was going wrong: SlatherOrg/slather#347

@Corrob Corrob self-assigned this Feb 5, 2019
@Corrob
Copy link
Contributor

Corrob commented Feb 7, 2019

I can successfully collect code coverage locally with the following steps:

  • Pod install
  • Open Firebase.xcworkspace
  • Configure the test scheme to gather coverage
  • Run all tests
  • Run "slather coverage --html --scheme AllUnitTests_iOS --configuration=Debug --workspace Firebase.xcworkspace/ Firebase.xcodeproj/"
  • This produces
    Slathering...
    warning: 14 functions have mismatched data
    warning: 14 functions have mismatched data
    Database/App/iOS/FIRAppDelegate.m: 7 of 21 lines (33.33%)
    ...
    ../Firebase/Database/third_party/Wrap-leveldb/APLevelDB.mm: 170 of 285 lines (59.65%)
    Tested 8935/14687 statements
    Test Coverage: 60.84%
    Slathered

@paulb777
Copy link
Member Author

paulb777 commented Feb 7, 2019

@Corrob Awesome!

How do you process/visualize the data?

It's probably worth adding the instructions to the Coverage subsection to the Development section on the repo homepage and publicizing it to the team.

@Corrob
Copy link
Contributor

Corrob commented Feb 14, 2019

Sorry about the delay, had some other issues pop up.

Slather can also output HTML files that allow you to dig into the coverage.

slather coverage --html --scheme AllUnitTests_iOS --configuration=Debug --workspace Firebase.xcworkspace/ Firebase.xcodeproj/

produces all of these HTML files: https://drive.google.com/open?id=1pIteb1sHho3SeaicbXmSLVcmjRgsxFG0. You can open index.html to start.

I'll send a PR with the necessary changes along with putting it in the README. After that, I'll try to hook it into Travis.

@maksymmalyhin
Copy link
Contributor

maksymmalyhin commented Feb 28, 2019

@Corrob @paulb777 Here is the tool I mentioned - xcov.
It is not as popular as Slather, but it generated the output divided by modules without extra work.

Here is a simple version I used for testing (run from Example folder):
xcov --workspace Firebase.xcworkspace --scheme AllUnitTests_iOS --output_directory xcov_output

A sample output can be found here

@Corrob
Copy link
Contributor

Corrob commented Mar 7, 2019

This is great, Maksym! I really appreciate your fix and input. I think we should go with xcov. I will update my PR.

@maksymmalyhin
Copy link
Contributor

@Corrob I am happy to help!

@paulb777
Copy link
Member Author

paulb777 commented Nov 7, 2019

CocoaPods 1.9.0 adds pod lib lint support for collecting coverage. See CocoaPods/CocoaPods#9302

@ryanwilson ryanwilson changed the title Add coverage reporting to travis Add coverage reporting to CI May 4, 2020
@paulb777
Copy link
Member Author

paulb777 commented May 4, 2020

This will get easier after #2022 and we can build the frameworks dynamically since there have been at least historical data collection issues with static frameworks and coverage.

In the meantime, initial work could be done for GoogleUtilities.

@paulb777
Copy link
Member Author

paulb777 commented Sep 9, 2020

See CocoaPods/CocoaPods#10034 (comment) for a start at adding via the CocoaPods test spec.

@ryanwilson
Copy link
Member

Now that we have dynamic frameworks, this should be more straightforward.

@granluo
Copy link
Contributor

granluo commented Dec 3, 2020

xccov, introduced in WWDC19(video at around 0:50:52), could be another way to get the coverage data.
Slather is using profdata (testing binary generated by xcode) over app binary to calculate the coverage, while xccov is actually reading xcresult bundles generated by xcode.
I think xccov is preferred since it is identical to xcode result while slather needs additional calculations of profdata over app binaries.

@paulb777
Copy link
Member Author

Closing since this is now implemented. Please open more specific issues for any outstanding items.

@firebase firebase locked and limited conversation to collaborators Mar 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants