I am looking for a way to generate code coverage for a Swift package created using Swift Package Manager. On OS X I can achieve this using Xcode after running swift package generate-xcodeproj
and running the test suite under Xcode at which point I have the standard coverage tools available to me.
Are there any tools out in the wild for that allow this to happen on OS X and Linux?
To enable code coverage, click the scheme editor in the toolbar. Select the CodecovDemo scheme and choose Edit Scheme. Select the Test action on the left. Check the Code Coverage box to gather coverage data.
Enabling Code Coverage in Xcode Code coverage is enabled in the scheme editor. Click the Covered scheme and choose Edit Scheme.... Select Test on the left and check the checkbox Gather coverage data. That is it.
You can find it under the Reports navigator. (View menu > Navigators > Reports or ⌘ - command + 9 ). After you open it, under the latest Test report, you should find a Coverage report, click on that, and it will contain the coverage information of that test run.
This is actually possible by passing --enable-code-coverage
to swift test
$ swift test --enable-code-coverage
That will generate an .xctest
bundle in .build/x86_64-unknown-linux/debug/
and a profdata file in .build/x86_64-unknown-linux/debug/codecov/
on Linux which you are able to then pass along to llvm-cov
to generate a report.
e.g.
$ llvm-cov report .build/x86_64-unknown-linux/debug/PredicatePackageTests.xctest -instr-profile=.build/x86_64-unknown-linux/debug/codecov/default.profdata -use-color
Which will generate a report like the following report:
See llvm-cov report --help
for more information, it can even produce HTML reports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With