2

xccov tool generates the unit test coverage report for covered lines of code only. So if example.swift file has 20 lines, and 10 is covered by unit tests the coverage will be 50%.

Karma (used in Angular 2 development) creates report not just for lines of code covered, but also statements, branches and functions.

Is it possible to config xccov, or is there a similar tool to achieve this in iOS development? Thanks!

Peter Lendvay
  • 565
  • 4
  • 22
  • Have a look at [this](https://sonarcloud.io/documentation/analysis/coverage/) documentation page. – Jeroen Heier Jun 18 '19 at 17:19
  • We are using [SonarQube's solution](https://github.com/SonarSource/sonar-scanning-examples/blob/master/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh) at the moment, but it does not solve the issue, the script generates report for lines of code covered only. – Peter Lendvay Jun 19 '19 at 07:06

1 Answers1

0

Xccov don't generate any coverage data. Xccov can read coverage reports from tool xcodebuild:

  1. To get coverage data you should select gather coverage data at your test scheme: edit_scheme

  2. At your CI script you can add flag -resultBundlePath to select folder where coverage data will save.

  3. Then you can use xccov to get following information:

    • Overall target coverage by xccov view --only-targets report.xccovreport
    • Coverage by file xccov view --files-for-target target_name report.xccovreport
    • Coverage for each function xccov view --func- tions-for-file name_or_path report.xccovreport
    • Raw coverage data line by line xccov view --file file_name report.xccovarchive

result

  1. You can use --json flag to analyze results by script.

For more information about xccov you can read man xccov or watch the WWDC session What's New in Testing

So, xccov give you statistics for functions out the box. If you want more. For example, statistic for statements and branches you can create script by yourself using SourceKit and xccov data. SourceKit can give an information about AST of source code and where statement are located. By the location you can match information about coverage through xccov report.

Anton Vlasov
  • 1,372
  • 1
  • 10
  • 18
  • Thanks, but your steps don't help. It clearly shows the report for lines covered only. Your last paragraph is what I need, but your statement "you can create a script by yourself using SourceKit and xcciv data" is like saying "you create an application writing code". While it's true, does not help at all. – Peter Lendvay Jul 02 '19 at 14:31